Can anyone give me an example that uses onResume()
in Android?
Also, if I want to restart the activity at the end of the execution of another, which met
onResume()
is one of the methods called throughout the activity lifecycle. onResume()
is the counterpart to onPause()
which is called anytime an activity is hidden from view, e.g. if you start a new activity that hides it. onResume()
is called when the activity that was hidden comes back to view on the screen.
You're question asks abou what method is used to restart an activity. onCreate()
is called when the activity is first created. In practice, most activities persist in the background through a series of onPause()
and onResume()
calls. An activity is only really "restarted" by onRestart()
if it is first fully stopped by calling onStop()
and then brought back to life. Thus if you are not actually stopping activities with onStop()
it is most likley you will be using onResume()
.
Read the android doc in the above link to get a better understanding of the relationship between the different lifestyle methods. Regardless of which lifecycle method you end up using the general format is the same. You must override the standard method and include your code, i.e. what you want the activity to do at that point, in the commented section.
@Override
public void onResume(){
//will be executed onResume
}