Tuesday, 24 November 2015

Android application logout after 15 min

Here i just made the code the application should come out when it is not used till 15 minutes

for counting i have taken counter


CountDownTimer timer = new CountDownTimer(15 *60 * 1000, 1000) {

       public void onTick(long millisUntilFinished) {
          //Some code
        Log.d("timer", "--"+millisUntilFinished);
       }

       public void onFinish() {
          //Logout
        finish();
        Log.d("***********", "logout");
       }
    };


then i just calling the timer when it goes to sleep

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d("***********", "onPause");
timer.start();
}



meanwhile if the application started again it means like resume, it should cancel

 @Override protected void onResume()
{ Log.d("***********", "onresume");
 super.onResume(); timer.cancel();
 }


No comments:

Post a Comment