Android Activity Lifecycle Methods Executed Sequence

Naved shaikh
2 min readDec 31, 2020

--

What is Android Activity?

Android Activity is an application component which creates a default window on screen, where we can place different components such as button, text view, spinner etc.

Diagram of Android Activity Lifecycle:

Android Activity Lifecycle is controlled by 7 methods those are as follows:

  • onCreate() : called when the activity is first created.
  • onStart() : called when activity is becoming visible to user.
  • onResume() : called when activity will start interacting with user.
  • onPause() : called when activity is not visible to user.
  • onStop() : called when activity is no longer visible to user.
  • onRestart() : called after your activity is stopped, prior to start.
  • onDestroy() : called before the activity gets destroyed.

Android Activity Lifecycle methods execution sequence:

Scenario 1: (Single Activity)

User launched the app (activity gets created)

  • onCreate()
  • onStart()
  • onResume()

User pressed the back button

  • onPause()
  • onStop()
  • onDestroy()

Scenario 2: (Between two different Activity eg. “A” to “B”)

User launched the app (activity “A” gets created)

  • ActivityA onCreate()
  • ActivityA onStart()
  • ActivityA onResume()

User navigate from Activity A to B

  • ActivityA onPause()
  • ActivityB onCreate()
  • ActivityB onStart()
  • ActivityB onResume()
  • ActivityA onStop()

User pressed back button (currently on Activity B)

  • ActivityB onPause()
  • ActivityA onRestart()
  • ActivityA onStart()
  • ActivityA onResume()
  • ActivityB onStop()
  • ActivityB onDestroy()

User again pressed back button (currently on Activity A)

  • ActivityA onPause()
  • ActivityA onStop()
  • ActivityA onDestroy()

--

--

No responses yet