Activity launch modes: Android

Gaurav Rajput
7 min readJan 3, 2021

To understand launch modes, lets first understand

What is Task?

What is back stack?

What is task-Affinity?

Task means stack of activities. Stack basically works on last in first out the concept, so the activity that is at the top of the stack ( which comes last ) will be poped ( out of stack) first. In the Android system, as you start an activity, it goes into a stack . And when you press the back button, this activity is popped from the stack given in the below image.

This stack is called Back Stack here.

Here let's assume Activity 1 is starting Activity 2 , so Activity 1 will be stopped and Activity 2 will start. But as soon as you press back button Activity 2 will be destroyed and Activity 1 resumes.

But how androids restoreActivity 1 ?

The Android system retains its state (such as scroll position and text entered into forms, etc.) and resumes it from there.

Another question :

What will happen with this stack if the user presses the home button?

The answer is, as soon as the user presses the home button, the current activity will be stopped, and this whole task (let's say Task A) will be in the background, and all activities state are…

--

--