Android Activity Life Cycle
Android is designed to empower users and let them use apps in a intuitive way. To provide the best user experience, you should know how to manage component lifecycles.
A component can be an Activity, a Fragment, a Service, the Application itself. The component has a lifecycle, during which it transit through states. Whenever a transition happens, the system notifies you via a lifecycle callback method.
Lets first start with the basic understanding or an overview of what's happening inside the Activity.
Before the activity is launched ,it has to be created .This happens in onCreate() method.
onStart() is called when the activity will be read to be visible to user.
When the activity is active or the user is interacting with the activity it moves to onResume()
When the user moves to different activity or different application, activity moves into onPause()
If the user doesn't return to the activity for a longer time then , onStop() called and then onDestroy() called.
What happens if the user returns to the Activity again.
If the user comes back to the activity before it’s destroyed, then the activity is restarted via the onRestart() method and it moves back into the start state and other callback method are called accordingly .
If the user comes back to the activity after its destroyed ,then the activity is created again and the other callback method are called accordingly .