Basically, Activity's lifecycle methods have their times of execution.
See below:
onCreate()
: This is the first function to execute in an Activity. It is usually responsible for loading XML layouts and other initialization operations. It is executed only once;
onStart()
: Is called immediately after the onCreate () - and also when an Activity that was in the background returns to focus,
onResume()
: Just like onStart (), it is invoked at Activity initialization and also when Activity returns to focus. What's the difference between the two? OnStart () is only called when Activity was no longer visible and resumes focus, onResume () is called in "focus resumes";
onPause()
: This is the first function to be invoked when the Activity loses focus (this occurs when a new Activity is started);
onStop()
: Only called when Activity is completely hidden by another Activity;
onDestroy()
: The last function to execute. After it, Activity is considered "dead" - meaning it can not be re-released. If the user re-requests this Activity, a new object will be constructed;
onRestart()
: Call immediately before onStart (), when an Activity returns to focus after it is in the background.
Source:
Article
Understanding the life cycle of an Android application | DEVMEDIA