@@ -336,10 +336,10 @@ it can also be set as a raw string.
336336</p></dd>
337337
338338<dt><a name="lmode"></a>{@code android:launchMode}</dt>
339- <dd>An instruction on how the activity should be launched. There are four modes
339+ <dd>An instruction on how the activity should be launched. There are four modes
340340that work in conjunction with activity flags ({@code FLAG_ACTIVITY_*} constants)
341- in {@link android.content.Intent} objects to determine what should happen when
342- the activity is called upon to handle an intent. They are:
341+ in {@link android.content.Intent} objects to determine what should happen when
342+ the activity is called upon to handle an intent. They are:</p>
343343
344344<p style="margin-left: 2em">"{@code standard}"
345345<br>"{@code singleTop}"
@@ -351,56 +351,110 @@ The default mode is "{@code standard}".
351351</p>
352352
353353<p>
354- The modes fall into two main groups, with "{@code standard}" and
355- "{@code singleTop }" activities on one side, and "{@code singleTask }" and
356- "{@code singleInstance}" activities on the other. An activity with the
357- "{@code standard}" or "{@code singleTop}" launch mode can be instantiated
358- multiple times. The instances can belong to any task and can be located
359- anywhere in the activity stack. Typically, they're launched into the task
360- that called
354+ As shown in the table below, the modes fall into two main groups, with
355+ "{@code standard }" and "{@code singleTop }" activities on one side, and
356+ "{@code singleTask}" and "{@code singleInstance}" activities on the other.
357+ An activity with the "{@code standard}" or "{@code singleTop}" launch mode
358+ can be instantiated multiple times. The instances can belong to any task
359+ and can be located anywhere in the activity stack. Typically, they're
360+ launched into the task that called
361361<code>{@link android.content.Context#startActivity startActivity()}</code>
362- (unless the Intent object contains a
363- <code>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</code>
364- instruction, in which case a different task is chosen — see the
362+ (unless the Intent object contains a
363+ <code>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</code>
364+ instruction, in which case a different task is chosen — see the
365365<a href="#aff">taskAffinity</a> attribute).
366366</p>
367367
368368<p>
369- In contrast, "{@ code singleTask} " and "{@ code singleInstance} " activities
370- can only begin a task. They are always at the root of the activity stack.
371- Moreover, the device can hold only one instance of the activity at a time
369+ In contrast, "< code> singleTask</code> " and "< code> singleInstance</code> " activities
370+ can only begin a task. They are always at the root of the activity stack.
371+ Moreover, the device can hold only one instance of the activity at a time
372372— only one such task.
373373</p>
374374
375375<p>
376376The "{@code standard}" and "{@code singleTop}" modes differ from each other
377- in just one respect: Every time there's new intent for a "{@code standard}"
378- activity, a new instance of the class is created to respond to that intent.
377+ in just one respect: Every time there's a new intent for a "{@code standard}"
378+ activity, a new instance of the class is created to respond to that intent.
379379Each instance handles a single intent.
380- Similarly, a new instance of a "{@code singleTop}" activity may also be
381- created to handle a new intent. However, if the target task already has an
382- existing instance of the activity at the top of its stack, that instance
383- will receive the new intent (in an
380+ Similarly, a new instance of a "{@code singleTop}" activity may also be
381+ created to handle a new intent. However, if the target task already has an
382+ existing instance of the activity at the top of its stack, that instance
383+ will receive the new intent (in an
384384<code>{@link android.app.Activity#onNewIntent onNewIntent()}</code> call);
385385a new instance is not created.
386- In other circumstances — for example, if an existing instance of the
387- "{@code singleTop}" activity is in the target task, but not at the top of
388- the stack, or if it's at the top of a stack, but not in the target task
386+ In other circumstances — for example, if an existing instance of the
387+ "{@code singleTop}" activity is in the target task, but not at the top of
388+ the stack, or if it's at the top of a stack, but not in the target task
389389— a new instance would be created and pushed on the stack.
390- </p>
390+ </p>
391391
392392<p>
393- The "{@code singleTask}" and "{@code singleInstance}" modes also differ from
394- each other in only one respect: A "{@code singleTask}" activity allows other
395- activities to be part of its task. It's at the root of the activity stack,
396- but other activities (necessarily "{@code standard}" and "{@code singleTop}"
397- activities) can be launched into the same task. A "{@code singleInstance}"
398- activity, on the other hand, permits no other activities to be part of its
399- task. It's the only activity in the task. If it starts another activity,
400- that activity is assigned to a different task — as if {@code
393+ The "{@code singleTask}" and "{@code singleInstance}" modes also differ from
394+ each other in only one respect: A "{@code singleTask}" activity allows other
395+ activities to be part of its task. It's always at the root of its task, but
396+ other activities (necessarily "{@code standard}" and "{@code singleTop}"
397+ activities) can be launched into that task. A "{@code singleInstance}"
398+ activity, on the other hand, permits no other activities to be part of its task.
399+ It's the only activity in the task. If it starts another activity, that
400+ activity is assigned to a different task — as if {@code
401401FLAG_ACTIVITY_NEW_TASK} was in the intent.
402402</p>
403403
404+ <table>
405+ <tr>
406+ <th>Use Cases</th>
407+ <th>Launch Mode</th>
408+ <th>Multiple Instances?</th>
409+ <th>Comments</th>
410+ </tr>
411+ <tr>
412+ <td rowspan="2" style="width:20%;">Normal launches for most activities</td>
413+ <td>"<code>standard</code>"</td>
414+ <td>Yes</td>
415+ <td>Default. The system always creates a new instance of the activity in the
416+ target task and routes the intent to it.</td>
417+ </tr>
418+ <tr>
419+ <td>"<code>singleTop</code>"</td>
420+ <td>Conditionally</td>
421+ <td>If an instance of the activity already exists at the top of the target task,
422+ the system routes the intent to that instance through a call to its {@link
423+ android.app.Activity#onNewIntent onNewIntent()} method, rather than creating a
424+ new instance of the activity.</td>
425+ </tr>
426+ <tr>
427+ <td rowspan="2">Specialized launches<br>
428+ <em>(not recommended for general use)</em></td>
429+ <td>"<code>singleTask</code>"</td>
430+ <td>No</td>
431+ <td>The system creates the activity at the root of a new task and routes the
432+ intent to it. However, if an instance of the activity already exists, the system
433+ routes the intent to existing instance through a call to its {@link
434+ android.app.Activity#onNewIntent onNewIntent()} method, rather than creating a
435+ new one.</td>
436+ </tr>
437+ <tr>
438+ <td>"<code>singleInstance</code>"</td>
439+ <td>No</td>
440+ <td>Same as "<code>singleTask"</code>, except that the system doesn't launch any
441+ other activities into the task holding the instance. The activity is always the
442+ single and only member of its task.</td>
443+ </tr>
444+ </table>
445+
446+ <p>As shown in the table above, <code>standard</code> is the default mode and is
447+ appropriate for most types of activities. <code>SingleTop</code> is also a
448+ common and useful launch mode for many types of activities. The other modes
449+ — <code>singleTask</code> and <code>singleInstance</code> — are
450+ <span style="color:red">not appropriate for most applications</span>,
451+ since they result in an interaction model that is likely to be unfamiliar to
452+ users and is very different from most other applications.
453+
454+ <p>Regardless of the launch mode that you choose, make sure to test the usability
455+ of the activity during launch and when navigating back to it from
456+ other activities and tasks using the BACK key. </p>
457+
404458<p>For more information on launch modes and their interaction with Intent
405459flags, see the
406460<a href="{@docRoot}guide/topics/fundamentals.html#acttask">Activities and
0 commit comments