What Are Android Launch Modes?
Launch mode is an Android OS command that determines how an activity should be started. It specifies how every new action should be linked to the existing task. In Android, an app can have multiple tasks, and activities can behave differently based on their launch mode.
There are four launch modes for activity:
- Standard
- SingleTop
- SingleTask
- SingleInstance
Understanding the Back Stack
The back stack is a representation of how each new activity in a task adds an item to the stack. When the user presses or gestures Back, the current activity is destroyed, and the previous activity resumes. Understanding the back stack is fundamental to mastering Android launch modes.
1. Standard Launch Mode
This is the default launch mode of an activity. If you don't set any launch mode for your activity, it will use the standard mode by default. This mode creates a new instance of the activity every time, even if the activity instance is already present in the task.
For example, if we have activities A, B, C, and D, and launch activity B again:
Before: A → B → C → D
After: A → B → C → D → B
A new instance of B is created again, resulting in multiple instances on the stack.
<activity android:launchMode="standard" />2. SingleTop Launch Mode
If an instance of an activity already exists at the top of the current task, a new instance will not be created, and the Android system will route the intent information through the onNewIntent() method. If the instance is not at the top, a new instance will be created.
Example 1 — C is not at top: A → B → C → D → launching C creates: A → B → C → D → C
Example 2 — C is at top: A → B → C → D → C → launching C reuses: A → B → C → D → C (onNewIntent called)
<activity android:launchMode="singleTop" />3. SingleTask Launch Mode
An activity declared with launch mode as singleTask can have only one instance in the system (like a singleton). If the activity instance is not present, a new instance will be created. If the instance is already present, the onNewIntent() method will receive the callback.
Example: Stack A → B → C, launching D (singleTask) gives: A → B → C → D. Then launching B (singleTask) gives: A → B — with C and D destroyed.
This behavior is particularly useful when you want to ensure certain activities, like the root activity, are only created once.
<activity android:launchMode="singleTask" />Transform Your Publishing Workflow
Our experts can help you build scalable, API-driven publishing systems tailored to your business.
4. SingleInstance Launch Mode
This is similar to singleTask, except that no other activities will be created in the same task. If another activity is launched from a singleInstance activity, a new task will automatically be created for that new activity.
Case 1: Activities A → B → C exist, and D has singleInstance. Launching D creates:
- Task 1: A → B → C
- Task 2: D
Case 2: Launching D again routes intent through onNewIntent() — no new instance is created.
<activity android:launchMode="singleInstance" />Task Affinity and Multiple Tasks
In Android, the taskAffinity attribute allows you to assign a specific affinity to an activity, which determines in which task the activity should reside. By setting taskAffinity, Android developers can control which activities share the same task, helping create a better user experience when navigating through the app.
When a new activity is launched, the taskAffinity value is checked to determine whether the new activity should be part of an existing task or if a new task should be created. This feature is particularly important when dealing with singleTask and singleInstance launch modes.
State Restoration and Navigation
A key consideration for Android developers is how to handle state restoration when navigating between different tasks. When activities are recreated or brought back to the foreground, developers need to manage how the state is restored to provide a seamless user experience.
By using launch modes like singleTask and singleInstance, you can ensure that only a single instance of an activity exists across tasks, reducing redundancy and improving app efficiency. The onNewIntent() method plays a crucial role in restoring the state of an activity when it is relaunched.
Conclusion
Understanding Android launch modes is crucial for managing activity behavior and navigation in mobile app development. By choosing the right launch mode — standard, singleTop, singleTask, or singleInstance — developers can control how activities are instantiated and how they interact with the back stack, leading to optimized memory usage and a better user experience.




