Search code examples
androidonresume

Android onResume from Application


My client wants their app to always show a "WARNING" screen when the application starts or when it awakens from sleep. I've tried creating an onResume() event in my master activity (which every other activity inherits from), but this causes an endless loop:

  1. Activity is called, onResume() is fired
  2. Warning screen fires, causing the calling activity to be paused
  3. User clicks OK to accept the message, returning the user to the prior screen
  4. Activity is woken up
  5. Go to 1

Even if I could get around the endless loop, the Warning screen would fire whenever a new activity loads. This is what I like to call a Bad Thing.

Is there a way to mimic the onResume() event but at the application level rather than at the activity level, so that I can avoid these scenarios but still have the warning pop up on application wake?


Solution

  • Why not just use SharedPreferences.

    http://android-er.blogspot.com/2011/01/example-of-using-sharedpreferencesedito.html

    Store the time the popup is brought up, and if it was within 5 mins, or something, then don't pop it up.

    This will break your loop and not completely annoy the user.