CN

A Detailed Guide to Activity Launch Modes in Android

Word count: 2.7kReading time: 16 min
2019/09/01
loading

Technical review · 2026-10-13. The 2019 sequences remain historical examples. Task selection, affinity, and Recents behavior were checked against AOSP android-9.0.0_r1 and android-16.0.0_r1; Android 12 (API 31) singleInstancePerTask is added below. The old records lack a complete device build identifier, and no device rerun was performed for this review.

Android Activities have several important launch modes: standard, singleTop, singleTask, and singleInstance. Plenty of articles explain these modes. I wrote a small demo to show how they change the arrangement of activities in tasks. The newer singleInstancePerTask mode is covered afterward.

Ordinary navigation within a task is commonly LIFO. Below, A -> B denotes the sequence of launch actions; task contents are listed top first. Keep an eye on the task contents after each action; following the changes makes the differences easier to see. Repeating a launch action does not necessarily create an instance. A Task is not a process or necessarily one visible Recents card.

I put the demo on GitHub too: AndroidLunchModeTest. The reviewed snapshot is eaa1f987e332e0f85187a911ad9ae01cd20fff05, using compile/target SDK 29 and min SDK 26. Its package is com.example.lunchmodetest, whereas the historical sequences below retain com.example.launchmodetest.

Check all navigation targets for each case. In the snapshot, MainActivity.startSingleTopActivity launches SingleTaskActivity, and StandardActivity launches SingleInstanceWithAffinityActivity by default. Changing one target does not implement every sequence. The WithAffinity classes actually use empty affinity; SingleTopWithAffinityActivity does not even declare singleTop. Class names are not configuration evidence. The sample code was inspected for this review; the project was not modified or compiled.

The explanations assume the same user, ordinary foreground Activity launches, and no extra Intent flags unless stated. Updating the old project to target SDK 31+ also requires explicit android:exported for components with intent filters; use true for the Launcher entry.

standard Mode

The default mode creates a new instance in these examples, which launch from an Activity without additional Intent flags that change reuse behavior. The manifest mode alone does not describe every possible launch.

1
android:launchMode="standard"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 1. Launch  Activity
MainActivity

//Task contents
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity

//Task contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch StandardActivity
MainActivity -> StandardActivity -> StandardActivity

//Task contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

singleTop Mode

1
android:launchMode="singleTop"

If the selected task already has the target Activity instance at its top, that instance receives onNewIntent(). An instance lower in the same task is not reused by singleTop alone. “Top” means the selected task’s top, not a single global stack for the device.

Test 1: SingleTopActivity below the top

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 1. Launch  MainActivity
MainActivity

//Task contents
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity

//Task contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch SingleTopActivity
MainActivity -> StandardActivity -> SingleTopActivity
//Task contents
com.example.launchmodetest/.SingleTopActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------

// 4. Launch StandardActivity
MainActivity -> StandardActivity -> SingleTopActivity -> StandardActivity
//Task contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.SingleTopActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 5. Launch SingleTopActivity:
MainActivity -> StandardActivity -> SingleTopActivity -> StandardActivity -> SingleTopActivity
//Task contents
com.example.launchmodetest/.SingleTopActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.SingleTopActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

//The earlier SingleTopActivity is below StandardActivity, so this launch creates another instance.

Test 2: SingleTopActivity at the top

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 1. Launch  MainActivity
MainActivity
//Task contents
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity
//Task contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch SingleTopActivity
MainActivity -> StandardActivity -> SingleTopActivity
//Task contents
com.example.launchmodetest/.SingleTopActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 4. Launch SingleTopActivity
MainActivity -> StandardActivity -> SingleTopActivity -> SingleTopActivity
//Task contents
com.example.launchmodetest/.SingleTopActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

//SingleTopActivity receives a new intent; no new instance is created.

singleTask Mode

1
android:launchMode="singleTask"
  1. The system searches for a reusable task under the launch conditions, beyond just the caller’s current task. It creates a task if no suitable one is found.
  2. If the selected task contains the target instance, the system delivers the new intent to it and removes activities above it. Otherwise, a new instance may be added to the selected task with matching affinity.
  3. In the original example, omitting taskAffinity inherits the app’s default affinity, which can select an existing task. It does not mean “always stay in the current task,” nor does singleTask unconditionally require the target to be the root.

Android 9’s ActivityStarter.getReusableIntentActivity and ActivityStack.findTaskLocked consider the component, user, document intent, and rootAffinity. Android 16’s ActivityStarter also separates task selection, clearing, and instance reuse.

Test 1: singleTask with default affinity

The old “Without Affinity” label means no explicit attribute, so default affinity applies. The following preserves the original sequence and task contents.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 1. Launch  MainActivity:
MainActivity
//Task contents:
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity
//Task contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch SingleTaskActivity
MainActivity -> StandardActivity -> SingleTaskActivity
//Task contents:
com.example.launchmodetest/.SingleTaskActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 4. Launch StandardActivity
MainActivity -> StandardActivity -> SingleTaskActivity -> StandardActivity
//Task contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.SingleTaskActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 5. Launch SingleTaskActivity
MainActivity -> StandardActivity -> SingleTaskActivity -> StandardActivity -> SingleTaskActivity
//Task contents:
com.example.launchmodetest/.SingleTaskActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

//SingleTaskActivity receives a new intent; StandardActivity above it is removed.

Test 2: singleTask with empty affinity

Despite its name, SingleTaskWithAffinity declares android:taskAffinity="": no affinity. It cannot match an ordinary task through shared affinity, so the first launch creates a task when no reusable target task exists. Later launches can still match the target component and reuse its task; an empty affinity does not force a new task every time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 1. Launch  MainActivity
MainActivity

//Task 0 contents:
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity

//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch SingleTaskWithAffinity
MainActivity -> StandardActivity -> SingleTaskWithAffinity

//Task 1 contents:
com.example.launchmodetest/.SingleTaskWithAffinity
//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 4. Launch StandardActivity
MainActivity -> StandardActivity -> SingleTaskWithAffinity -> StandardActivity

//Task 1 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.SingleTaskWithAffinity
//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 5. Launch SingleTaskWithAffinity
MainActivity -> StandardActivity -> SingleTaskWithAffinity -> StandardActivity -> SingleTaskWithAffinity

//Task 1 contents:
com.example.launchmodetest/.SingleTaskWithAffinity
//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------

singleTask Summary

  1. These configurations select different Tasks in the example. A Task is not the old framework ActivityStack container, so this does not imply creation of a new ActivityStack.
  2. A normal launch of StandardActivity from SingleTaskWithAffinity can place it in the same task despite a different default affinity.
  3. Launching SingleTaskWithAffinity again from another task can reuse its task and instance, removing activities above it.
  4. A separate Recents card depends on Recents management, exclusion flags, and system behavior, not just the class name or empty affinity.

singleInstance Mode

1
android:launchMode="singleInstance"

The singleInstance task contains only that Activity. Other activities it starts must use another task. The system looks for an existing instance of the same target component for the same user; this is not a Java singleton shared across users, work profiles, or process death.

My notes about a task being absent or present in “multitasking” describe the Recents cards I saw, not whether the Task exists. They are historical UI observations, not guarantees of the launch mode.

Test 1: singleInstance with default affinity

No explicit taskAffinity is supplied, so the default applies. StandardActivity returning to Task 0 below is this example’s task-selection result; another launch can select a different existing task or create one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
taskAffinity=com.example.launchmodetest

// 1. Launch MainActivity
MainActivity

//Task 0 contents
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity

//Task 0 contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch SingleInstanceActivity
MainActivity -> StandardActivity -> SingleInstanceActivity

//Task 1 contents(historical observation: no separate Recents card)
com.example.launchmodetest/.SingleInstanceActivity
//Task 0 contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 4. Launch StandardActivity
MainActivity -> StandardActivity -> SingleInstanceActivity -> StandardActivity

//Task 1 contents(historical observation: no separate Recents card)
com.example.launchmodetest/.SingleInstanceActivity
//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 5. Launch SingleInstanceActivity
MainActivity -> StandardActivity -> SingleInstanceActivity -> StandardActivity -> SingleInstanceActivity

//Task 1 contents: (historical observation: no separate Recents card)
com.example.launchmodetest/.SingleInstanceActivity
//Task 0 contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 6. Launch StandardActivity
MainActivity -> StandardActivity -> SingleInstanceActivity -> StandardActivity -> SingleInstanceActivity -> StandardActivity

//Task 1 contents: (historical observation: no separate Recents card)
com.example.launchmodetest/.SingleInstanceActivity
//Task 0 contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 7. Launch SingleInstanceActivity
MainActivity -> StandardActivity -> SingleInstanceActivity -> StandardActivity -> SingleInstanceActivity -> StandardActivity -> SingleInstanceActivity

//Task 1 contents (historical observation: no separate Recents card)
com.example.launchmodetest/.SingleInstanceActivity
//Task 0 contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

singleInstance Summary

  1. singleInstance owns a dedicated task, but does not guarantee that its Recents card is hidden.
  2. Reuse matches the user and target component, allowing delivery of onNewIntent. Configuration changes or process recreation can still create a new client-side Activity object.
  3. Activities started from it use another task selected by the system, not necessarily “the previous task.”

For example, Android 9 RecentTasks.findRemoveIndexForAddTask and Android 16 RecentTasks compare nonempty affinity, base intents, and other conditions when deduplicating/trimming ordinary task entries. Shared affinity can therefore affect cards, but the old notes do not establish the precise cause of each device observation.

Test 2: singleInstance with empty affinity

Here too, the old “With Affinity” label refers to android:taskAffinity="", meaning no affinity. The separate Recents card is retained as a historical observation; empty affinity does not disable singleInstance reuse.

1
2
taskAffinity=null

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 1. Launch  MainActivity
MainActivity

//Task 0 contents:
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 2. Launch StandardActivity
MainActivity -> StandardActivity

//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 3. Launch SingleInstanceWithAffinityActivity
MainActivity -> StandardActivity -> SingleInstanceWithAffinityActivity

//Task 1 contents:(historical observation: a Recents card is shown)
com.example.launchmodetest/.SingleInstanceWithAffinityActivity

//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 4. Launch StandardActivity
MainActivity -> StandardActivity -> SingleInstanceWithAffinityActivity -> StandardActivity

//Task 1 contents:(historical observation: a Recents card is shown)
com.example.launchmodetest/.SingleInstanceWithAffinityActivity

//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 5. Launch SingleInstanceWithAffinityActivity
MainActivity -> StandardActivity -> SingleInstanceWithAffinityActivity -> StandardActivity -> SingleInstanceWithAffinityActivity

//Task 1 contents:(historical observation: a Recents card is shown)
com.example.launchmodetest/.SingleInstanceWithAffinityActivity

//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 6. Launch StandardActivity
MainActivity -> StandardActivity -> SingleInstanceWithAffinityActivity -> StandardActivity -> SingleInstanceWithAffinityActivity -> StandardActivity

//Task 1 contents:(historical observation: a Recents card is shown)
com.example.launchmodetest/.SingleInstanceWithAffinityActivity
//Task 0 contents
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

-------------------------------------------------------------------
// 7. Launch SingleInstanceWithAffinityActivity
MainActivity -> StandardActivity -> SingleInstanceWithAffinityActivity -> StandardActivity -> SingleInstanceWithAffinityActivity -> StandardActivity -> SingleInstanceWithAffinityActivity

//Task 1 contents:(historical observation: a Recents card is shown)
com.example.launchmodetest/.SingleInstanceWithAffinityActivity
//Task 0 contents:
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.StandardActivity
com.example.launchmodetest/.MainActivity

Since Android 12: singleInstancePerTask

Android 12 (API 31) added singleInstancePerTask. The Activity must be the task root, with one instance of that component per task; other activities can still join the task.

An ordinary repeat launch can reuse the task and clear activities above the target. Suitable MULTIPLE_TASK or NEW_DOCUMENT launches can create instances of the component in separate tasks. This differs from singleInstance, whose task contains only one Activity. Document modes and flags still interact, so one flag is not an unconditional guarantee of a new instance. The 2019 demo does not implement this mode.

Intent Flags and onNewIntent

Caller flags also affect the outcome. These combinations are particularly relevant to the examples:

Launch option Effect
SINGLE_TOP Reuse a target already at the selected task’s top; it does not automatically find it lower down and clear intervening pages
NEW_TASK Search for or create a task; it does not always create one
CLEAR_TOP Clear activities above the target; for a standard target without SINGLE_TOP or another reuse condition, the target itself can also be finished and recreated
NEW_TASK + CLEAR_TASK Clear the selected task’s old contents and make the new Activity its root; this is not an alias for CLEAR_TOP

See Android 16 ActivityStarter and Task.clearTopActivities. Background launches must also satisfy the applicable platform restrictions; launchMode does not grant background-start permission.

Reuse does not automatically consume new parameters. The Activity API documents that getIntent() still returns the previous Intent unless updated with setIntent. Process the new parameters in the callback. For example, inside an existing Activity class:

1
2
3
4
5
6
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
// Update the page from this Intent, sharing handling with the initial onCreate path.
}

This fragment illustrates Intent replacement, not a complete demo. Inspect onCreate/onNewIntent, getTaskId, and task contents before and after each operation to distinguish a new task, a new Activity, and a reused instance receiving another Intent. The original am_new_intent is a historical system event name, not a guaranteed current log tag.

Key Concepts

TaskAffinity

taskAffinity expresses an Activity’s affinity for a task. It participates in task selection and permitted reparenting; it does not force all activities with the same affinity into one task. A normal startActivity call can place activities with different affinities in the caller’s task, and one app can have several tasks.

Configuration Meaning
No activity taskAffinity attribute Inherit <application> affinity; the app default is its package name
android:taskAffinity="" No affinity, commonly represented as null in dumps
android:taskAffinity="com.example.launchmodetest.detail" An explicit nonempty affinity, not a Task ID

NEW_TASK-related searches and allowTaskReparenting use affinity together with component, user, flags, and task state. Affinity grants no permissions and does not make apps share a process. See the activity manifest reference.

Relationships: ActivityRecord, TaskRecord, ActivityStack

These names describe the older AMS container model used by the historical diagrams. They are not unchanged across all Android versions.

  1. ActivityRecord is a server-side Activity record in system_server. One Activity class can have multiple records; a record does not imply that one Java Activity object remains alive forever in the app process.
  2. TaskRecord groups ActivityRecords in a task. Ordinary navigation commonly behaves as LIFO, while clearing, reordering, and cross-task launches change the sequence.
  3. ActivityStack manages TaskRecords; ActivityDisplay groups stacks for a display, coordinated by ActivityStackSupervisor. There is not always one display object, nor a fixed total of Home/App/Recents stacks.

Historical Activity containers
Historical ActivityRecord relationships

The referenced Gityuan article was published in 2017. Its container relationships help explain the old model; the diagram is not a modern multi-window architecture map.

The next image preserves the original adb shell dumpsys activity containers output. It shows display 0 and numStacks=5, already contradicting a fixed “three stacks” rule. Task 671 contains several ActivityRecords. Task IDs, stack IDs, and PIDs identify different things.

Historical activity containers dump

In android-16.0.0_r1, containers include RootWindowContainer, DisplayContent, TaskDisplayArea, Task, and TaskFragment. Task itself extends TaskFragment. Root/leaf tasks, nested Tasks, and embedded activities prevent a mechanical three-level replacement of the old diagram. TaskRecord and ActivityStack are not stable cross-version APIs. Dump commands and formatting also vary; no new device dump was produced for this review.

Activity Types

These are Android 9 WindowConfiguration activity-type constants, not launch modes. For example, type=standard and android:launchMode=”standard” describe different dimensions.

1
2
3
4
5
6
7
8
9
10
/** Activity type is currently not defined. */
public static final int ACTIVITY_TYPE_UNDEFINED = 0;
/** Standard activity type. Nothing special about the activity... */
public static final int ACTIVITY_TYPE_STANDARD = 1;
/** Home/Launcher activity type. */
public static final int ACTIVITY_TYPE_HOME = 2;
/** Recents/Overview activity type. There is only one activity with this type in the system. */
public static final int ACTIVITY_TYPE_RECENTS = 3;
/** Assistant activity type. */
public static final int ACTIVITY_TYPE_ASSISTANT = 4;

Android 16 WindowConfiguration additionally defines ACTIVITY_TYPE_DREAM = 5. These framework role classifications are not a way to declare an app as Home, Recents, or Assistant through launchMode.

If you found this useful, please share it. I hope it helps others too.

About Me && Blog

For my introduction and related articles:

  1. About me
  2. Blog navigation
  3. Android performance optimization: skills and tools
  4. Android performance community: The paid community stopped operating in 2026 and no longer accepts new members; this link preserves its history.

WeChat QR code

CATALOG
  1. 1. standard Mode
  2. 2. singleTop Mode
    1. 2.1. Test 1: SingleTopActivity below the top
    2. 2.2. Test 2: SingleTopActivity at the top
  3. 3. singleTask Mode
    1. 3.1. Test 1: singleTask with default affinity
    2. 3.2. Test 2: singleTask with empty affinity
    3. 3.3. singleTask Summary
  4. 4. singleInstance Mode
    1. 4.1. Test 1: singleInstance with default affinity
    2. 4.2. singleInstance Summary
    3. 4.3. Test 2: singleInstance with empty affinity
  5. 5. Since Android 12: singleInstancePerTask
  6. 6. Intent Flags and onNewIntent
  7. 7. Key Concepts
    1. 7.0.1. TaskAffinity
    2. 7.0.2. Relationships: ActivityRecord, TaskRecord, ActivityStack
    3. 7.0.3. Activity Types
  • 8. About Me && Blog