The Android back stack is the ordered list of activities in a task, with the most recent one on top; pressing Back pops the top activity. Launch modes decide whether starting an activity creates a new instance on that stack or reuses an existing one. The four launch modes are standard, singleTop, singleTask and singleInstance, set in the manifest or through intent flags.
Understanding them explains behaviour such as why tapping a notification opens a duplicate screen, or why Back exits the app unexpectedly.
A task is a collection of activities a user interacts with to do something, such as composing an email. The activities are arranged in a back stack in the order they were opened. When you start an activity it is pushed on top; when the user presses Back it is popped and destroyed, and the previous one resumes.
Tasks appear in the recent apps screen. Moving an app to the background keeps its task and stack, so returning restores where the user left off, unless the system has killed the process.
standard is the default. Each start creates a new instance, even if one of the same class is already on top.
Use it for screens where multiple copies make sense, such as a detail screen that is opened for different items.
With singleTop, if an instance already sits at the top of the stack, the system reuses it and calls onNewIntent() instead of creating another. If the instance is anywhere else in the stack, a new one is created.
It suits a search screen that may be re-launched from a notification or a button.
singleTask allows only one instance of the activity in its task. If it already exists, the system brings that task forward, delivers onNewIntent() and destroys every activity above it.
This fits the root screen of an app, such as a main hub. Note that the activity is not guaranteed to start a new task. It does so only when its taskAffinity differs from the starting task. Since Android 10, behaviour for activities in the background has also become more restricted, so test on current versions.
singleInstance is like singleTask, but the activity is the only one in its task. Any activity it starts goes into a different task. It is rare and mainly used for special cases such as an incoming-call screen. The related singleInstancePerTask mode, added in Android 12, allows one instance per task rather than per device.
| Mode | New instance each start | Reuses existing | Alone in task |
|---|---|---|---|
standard | Yes | No | No |
singleTop | Unless already on top | If on top | No |
singleTask | No | Anywhere in its task | No |
singleInstance | No | Yes | Yes |
You can also choose the behaviour at the call site with intent flags.
Common flags are:
FLAG_ACTIVITY_NEW_TASK: start in a new task, needed when starting an activity from a non-activity context.FLAG_ACTIVITY_CLEAR_TOP: if the activity exists, pop everything above it.FLAG_ACTIVITY_SINGLE_TOP: the flag form of singleTop.FLAG_ACTIVITY_CLEAR_TASK: clear the task before starting; used with NEW_TASK, for example after logout.When both a flag and a manifest mode apply, the flag usually wins.
When an existing instance is reused, the new intent arrives in onNewIntent(), and getIntent() still returns the original one unless you call setIntent().
singleTask makes back navigation surprising. Prefer standard with proper navigation graphs.PendingIntent with an explicit task stack, for example with TaskStackBuilder, so Back goes to a sensible parent.standard. Every start creates a new instance on top of the current task.
singleTop reuses an instance only when it is at the top of the stack. singleTask reuses it anywhere in the task and removes everything above it.
Start the target with FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK, then call finish() on the current activity if needed.
Compose apps usually use one activity and a navigation library, so launch modes mostly matter for the entry activity and deep links.
The back stack is the history of activities in a task, and launch modes control whether a start creates a new instance or reuses one. Use standard by default, singleTop to avoid duplicate top screens, and singleTask sparingly for root screens. Handle onNewIntent() whenever an instance can be reused.