Question

On Android, I'm trying to catch the event where my app comes back to the foreground from the background. In other words, the app was active, then the user minimized it (by clicking the home button or starting another app or something), and then the user runs the app again.

I can add the onRestart() method to an activity as follows:

@Override
public void onRestart() {
    super.onRestart();

    Log.d("MAIN", "onRestart called.");
}

But this only works when that specific activity is the active one when the user minimizes the app.

Is there a way to catch this for the whole app somehow? Or do I need to add onRestart to every single activity I have? (I suppose I could create a superclass on which all the other activities are based).

Thanks!

Was it helpful?

Solution

Is there a way to catch this for the whole app somehow?

No, because there is no concept of an app "restarting".

Or do I need to add onRestart to every single activity I have?

Presumably. Or, find a way to avoid needing to "catch the event where [your] app comes back to the foreground from the background".

OTHER TIPS

I think the method you need is void onResume()

here is there android developers page for activities , check the "Implementing the lifecycle callbacks" part of the page .
http://developer.android.com/guide/components/activities.html

hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top