Basically, Activity’s lifecycle methods have their moments of execution.
See below:
onCreate()
: It is the first function to be executed in an Activity. It is usually responsible for loading XML layouts and other boot operations. Is executed only once;
onStart()
: It is called immediately after onCreate() - and also when a background activity is back in focus;
onResume()
: Just like onStart(), it is called on the Activity startup and also when an Activity has focus again. What is the difference between the two? onStart() is only called when Activity is no longer visible and re-focuses, onResume() is called in the "focus resumes";
onPause()
: It is the first function to be invoked when Activity loses focus (this occurs when a new Activity is started);
onStop()
: It is only called when Activity is completely covered up by another Activity;
onDestroy()
: The last function to be executed. After it, Activity is considered "dead" - that is, it can no longer be relaunched. If the user requests this Activity again, a new object will be built;
onRestart()
: Call immediately before onStart(), when an Activity again focuses after being in the background.
Source:
Article
Understanding the life cycle of an Android app | DEVMEDIA
Thank you very much @Antóniomacave for the enlightening response.
– Eduardo Mendes