-4

I want to logout automatically if app is idle for some time , like session time out , how it can be done in android app?

Michael
  • 57,169
  • 9
  • 80
  • 125
  • How are you maintaining session in APP, tell us that then we can give you an answer. – Nitin Misra Dec 19 '14 at 06:50
  • for now we are storing token into shared pref and using it for each request, but want to delete it if app is ideal for some time. – sandeep jadhav Dec 19 '14 at 06:54
  • you can use a global timer reference a `countdown timer` and in each activity `onResume` method reset you `timer` and in your `timer` logic when countdown finishes `invalidate` your preferences – Nitin Misra Dec 19 '14 at 06:57
  • Thanks , Its solved my problem only instead of using onResume() used onUserInteraction() method to reset timer. – sandeep jadhav Dec 19 '14 at 12:29

2 Answers2

1

Use TimerTask to increment the session timeout variable.

If it reaches some threshold value call finish() in your Activity

Reset the session timeout variable in onUserInteraction() of your Activity.

Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59
  • But I want to invalidate session if app is ideal for some time like 15 minute etc , don want to invalidate session when user is using app. – sandeep jadhav Dec 19 '14 at 06:59
  • Where you storing session values ? If it is SharedPreferences , clear it when you timeout variable reaches a limit value(Say 15mints) – Don Chakkappan Dec 19 '14 at 07:02
0

You can achieve this in below method

@Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }
yuva ツ
  • 3,707
  • 9
  • 50
  • 78