How would an Activity know if it has just been brought back from either being minimized (e.g., the user pressed Home and did other stuff and then brought the app back into the foreground afterwards) or from the screen timing out and the screen going black?
If I hit Home while on an app, then OnDestroy doesn’t necessarily fire, does it? Same goes for if the screen times out. So it doesn’t seem there will be a way to set a flag as soon as the screen leaves the foreground.
OnResume seems to fire all the time, definitely not just when an Activity is brought back to the foreground.
Watching LogCat I don’t see anything that gives me any hints, so here I am…
I think this will explain everything you need:
http://developer.android.com/reference/android/app/Activity.html
But basically: the
onResume()will always fire when the activity comes back to foreground,and the
onPause()will fire when activity goes to background (or destroyed). So overriding both is the answer.