Use AlarmManager
Basic idea is, you override onPause()
set an alarm in it for 5 minutes, and when that alarm returns, "log-out" the user. If the user returns you can cancel that alarm (override onResume()
Here is a good thread explaining usage of AlarmManager
with code for cancelling and scheduling new alarms as well as handling the callbacks.
If you want to do it simpler, you can keep track of a static timestamp variable. Update this variable in your onPause()
, then when the user returns (onResume()
) check the time of this variable, see if 5 minutes has passed, if it has redirect user back to login