Reputation: 6952
While we are having onStart method, what is the purpose of onRestart method?
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onRestart() {
super.onRestart();
}
Upvotes: 20
Views: 31178
Reputation: 14053
Adding to NightFury's answer. The onRestart() method is a callback method in the Android Activity lifecycle that is called when the activity is restarting after having been stopped.
Some use cases:
Upvotes: 0
Reputation: 13546
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.
Upvotes: 11
Reputation: 1001
Only 100% sure that onRestart
is called is when you navigate away and then navigate back to the activity.
On the other hand, when you press home button and the app moved to background, there is no way we can know whether the app is destroyed by OS to claim back resources or it is still reside on memory. If the app is destroyed then onCreate
will be called. Otherwise if the app is still available in memory then onRestart
will be called.
Upvotes: 2
Reputation: 3138
onRestart()
is called after onStop()
when the current activity is being re-displayed to the user.
e.g. The user has navigated back to it.
Upvotes: 0
Reputation: 4039
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
Upvotes: 9
Reputation: 2452
Here is the activity lifecycle there is your onStart()
and onRestart()
methods with explanations
more info here
Upvotes: 23
Reputation: 380
According to this
Note: Because the system retains your Activity instance in system memory when it is stopped, it's possible that you don't need to implement the onStop() and onRestart() (or even onStart() methods at all. For most activities that are relatively simple, the activity will stop and restart just fine and you might only need to use onPause() to pause ongoing actions and disconnect from system resources.
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().
Upvotes: 1
Reputation: 2132
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.
Upvotes: 3