Understand the Activity Lifecycle

When the user navigates from one activity to another or even in single-page activity, the application will pass through various states. These states are onCreate, onStart, onResume, onPause, onStop, onDestroy. Which are totally responsible for the behavior of the activities in the application.
Activity Lifecycle States (Methods)
onCreate()
Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity’s previously frozen state, if there was one. Always followed by onStart().
onStart()
Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.
onResume()
Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it. Always followed by onPause().
onPause()
Called as part of the activity lifecycle when an activity is going into the background but has not (yet) been killed. The counterpart to onResume(). When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A’s onPause() returns, so be sure to not do anything lengthy here.
onStop()
Called when you are no longer visible to the user. You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity.
onRestart()
Called after your activity has been stopped, prior to it being started again. Always followed by onStart().
onDestroy()
The final call you receive before your activity is destroyed. This can happen either because the activity is finishing someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.
Activity Lifecycle Example
simple code shows the behavior of the activity. use this code snippet, run the app on Device or emulator, and then check your log by interacting or navigate/minimize/close the app. You will get a better idea of how these activity lifecycle states work.
Some Situations
- When open the app
onCreate() --> onStart() --> onResume()
- When back button pressed and exit the app
onPaused() -- > onStop() --> onDestory()
- When home button pressed
onPaused() --> onStop()
- After pressed home button when again open an app from the recent task list or clicking on the icon
onRestart() --> onStart() --> onResume()
- When open app another app from notification bar or open settings
onPaused() --> onStop()
- Back button pressed from another app or settings then the user can see our app
onRestart() --> onStart() --> onResume()
- When any dialog open on the screen
onPause()
- After dismissing the dialog or back button from the dialog
onResume()
Simplified Meanings
onCreate()
on Create And Prepare To Display
onStart()
on Visible
onResume()
on Begin Interaction
onPause()
on Pause Interaction
onStop()
on Invisible
onRestart()
on Prepare To Display
onDestroy()
on Finish
for more information check out Android Developer Documentation