Sitemap

Activity Lifecycle

Jun 18, 2021

--

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.

LifeCycle’s methods sequence

Get Sohan Gupta’s stories in your inbox

Join Medium for free to get updates from this writer.

onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onDestroy()

Activity Lifecycle Diagram

Lifecycle callbacks when one activity comes on top of another

Task

Starting activity2 from the activity1’s onCreate() method as follows

@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}

Note: onCreate() of activity1 is already called as activity2 is being called from there.

What happens when press back button on Activity 2: See all the callbacks of activity 1 and activity 2 in below diagram

--

--

Sohan Gupta
Sohan Gupta

Written by Sohan Gupta

Android | Java | Kotlin | Full Stack Developer