开发者

Create application session in android

开发者 https://www.devze.com 2023-04-10 04:44 出处:网络
My application require timeout of 10 min i.e. if there is no activity on the application from last 10 min, then either the application is terminated or login(Login credential in sqlite db) is shown.

My application require timeout of 10 min i.e. if there is no activity on the application from last 10 min, then either the application is terminated or login(Login credential in sqlite db) is shown.

I cam开发者_开发知识库e up with the approach of using thread with maintain perform the task but that approach is untidy approach.

Suggest me some better approach.


I would do this way.

  1. Save the current time (in millisec) to pref file in onPause();
  2. Retrieve the time from pref file and compare with current time in onResume();
  3. If the time difference is more than 10, just finish() the activity and ask for log in.


Use timer class to do this task / alternatively can use Alarm class for the same. Depends on requirement. Thread will certainly not be a good option.


You may use AsyncTask to do this job.

0

精彩评论

暂无评论...
验证码 换一张
取 消