How to start Login Activity if user wasn't active for 5 minutes:

↘锁芯ラ 提交于 2019-12-08 08:48:59

问题


I need to start the log in Activity if the user wasn't active for 5 minutes in the application ,without considering from what activity he left the application. (by not active for 5 minutes I mean that the user didn't commit any action to the server side)

I have a Date variable inside my Application class:

private Date timeOfLogin;

that's is saved when the user commits log in, in some point of usage the user can get a phone call or a mail and will leave the application. now this can happen on any screen of the application. And now when he turns on the application again /return to it after finishing his phone call I need to show the log in screen again and not his last activity if 5 or more minutes have passed.

How can it be done? do I have to override every onResume of each activity I have in the application and start the log in Activity if the difference between the timeOfLogin and current date is bigger then 5 minutes? or is there a better way to do that?

Any help would be appreciated.

Thanks.


回答1:


Have an activity that all of your other activities extend and put the logic in that activity's onResume. (You'll probably find this practice to be useful in a lot of other ways too)




回答2:


Create a CountDownTimer with 5 minute count down in your ResponseHandler class in the onFinish() show the login dialog. If there is any response cancel the timer and start again.



来源:https://stackoverflow.com/questions/15661557/how-to-start-login-activity-if-user-wasnt-active-for-5-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!