When do onRestart method get called in Android?

You can read all about the Activity's lifecycle on Android developers: http://developer.android.com/reference/android/app/Activity.html#onRestart()

Taken directly from there:

Called after onStop() when the current activity is being re-displayed to the user (the user has navigated back to it). It will be followed by onStart() and then onResume().

For activities that are using raw Cursor objects (instead of creating them through managedQuery(android.net.Uri, String[], String, String[], String), this is usually the place where the cursor should be requeried (because you had deactivated it in onStop().

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.


The onRestart() method will be called whenever the Activity comes back from the invisible state. Suppose, we pressed the home button of the device and coming back, this onRestart() will be invoked. For more info about this, please go through the documentation


One case of onRestart() being called is when user presses home button and comes to launcher screen. In this case, activity is not destroyed and pause/stop events are fired. When user opens your app again, onRestart() for that activity is called before onStart(). You can find example here.


Here is the activity lifecycle there is your onStart() and onRestart() methods with explanations

enter image description here

more info here

Tags:

Android