Android Application Lifecycle

Manura Lakshan
2 min readFeb 21, 2021

As a user navigates through the app, Activity instances in your app transition through different stages in their life-cycle. The Activity class provides a number of callbacks that allow the activity to know that a state has changed: that the system is creating, stopping, or resuming an activity, or destroying the process in which the activity resides. To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate() , onStart() , onResume(), onPause(), onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.

I grabbed activities of android app lifecycle,

  1. onCreate(): In this state, the activity is created.
  2. onStart(): This callback method is called when the activity becomes visible to the user.
  3. onResume(): The activity is in the foreground and the user can interact with it.
  4. onPause(): Activity is partially obscured by another activity. Another activity that’s in the foreground is semi-transparent.
  5. onStop(): The activity is completely hidden and not visible to the user.
  6. onRestart(): From the Stopped state, the activity either comes back to interact with the user or the activity is finished running and goes away. If the activity comes back, the system invokes onRestart().
  7. onDestroy(): Activity is destroyed and removed from the memory

Examples:

When you open the app it will go through below states:

• onCreate() –> onStart() –> onResume()

When you press the back button and exit the app

• onPause() → onStop() –> onDestory()

When you press the home button

• onPause() –> onStop()

After pressing the home button, again when you open the app from a recent task list

• onRestart() –> onStart() –> onResume()

Thank you very much for reading. #lovemedium and nice day.

--

--