I'm trying to implement some automatic logout code for my Application on Android.
I need to detect if all the activities belonging to an Application have entered the background as opposed to working with onPause()
and onResume()
for each individual activity. iOS has a helpful applicationDidEnterBackground:
method that I could utilize, but I'm unable to find a similar function in Android's Application
class.
One approach seems to be to have an AtomicInteger
counter and increment it once an activity becomes visible and decrement it when it's finished or onStop() gets called. So if the counter becomes zero, I can start a service that runs in the background and handles the logout. Is this how it's usually done?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…