Breaking News
Loading...

Session idle timeout in Google Android

12:01 PM
Control_Activity.java

package com.eae.time_out_application;
import android.app.Application;
import android.content.Intent;
import android.os.CountDownTimer;
import android.util.Log;

public class Control_Activity extends Application{

int count=0;
MyCounter timer;

private static final String TAG=Control_Activity.class.getName();

@Override
 public void onCreate()
 {
     super.onCreate();
      timer = new MyCounter(30000,1000);
      timer.start();
  }

  public void touch()
  {
     timer.start();
  }

   public class MyCounter extends CountDownTimer{
  
   public MyCounter(long millisInFuture, long countDownInterval) {
    super(millisInFuture, countDownInterval);
    }

   @Override
    public void onFinish() {
            System.out.println("Timer Completed.");
            Log.e("finish is called", "finish is called");
            Intent intent = new Intent();
            intent.setClass(Control_Activity.this, Login_Page.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
   }

   @Override
    public void onTick(long millisUntilFinished) {
           System.out.println("Timer  : " + (millisUntilFinished/1000));
        }
   }
  
  }

Control_Application.java

package com.eae.time_out_application;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RelativeLayout;

public class Control_Application extends Activity {

RelativeLayout mylayout;
private static final String TAG = Control_Application.class.getName();

 /**
     * Gets reference to global Application
     * @return must always be type of ControlApplication! See AndroidManifest.xml
  */
   public Control_Activity getApp()
    {
        return (Control_Activity )this.getApplication();
    }
   
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  //setContentView(R.layout.activity_control__application);
  
 }

 @Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  
 }

 @Override
  public void onUserInteraction()
  {
        super.onUserInteraction();
        getApp().touch();
        Log.d(TAG, "User interaction to "+this.toString());
        Log.e("My Activity Touched", "My Activity Touched");
   }

}

Login Page.java

package com.eae.time_out_application;

import android.app.Activity;
import android.os.Bundle;

public class Login_Page  extends Activity{

@Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.login_page);
 }

}


main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Control_Application" 
    android:id="@+id/totallayout">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="88dp"
        android:layout_marginTop="44dp"
        android:text="Button" />

    <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="55dp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignParentTop="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>



loginpage.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dip"
        android:text="Login" />

</LinearLayout>


Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eae.time_out_application"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name="com.eae.time_out_application.Control_Activity" >
        <activity
            android:name="com.eae.time_out_application.Control_Application"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity
            android:name="com.eae.time_out_application.Login_Page" />
    </application>

</manifest>



Simply copy and past the code and run it.

If u have any doubts please reply to me 

Thank You

0 komentar:

Post a Comment

 
Toggle Footer