Home | History | Annotate | Download | only in components
      1 page.title=
      2 parent.title=Activity
      3 parent.link=activities.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7 <div id="qv">
      8 
      9 <h2></h2>
     10 <ol>
     11 <li><a href="#ActivityState"> Activity </a></li></li>
     12 <li><a href="#ManagingTasks"></a>
     13   <ol>
     14     <li><a href="#TaskLaunchModes"></a></li>
     15     <li><a href="#Affinities"></a></li>
     16     <li><a href="#Clearing"></a></li>
     17     <li><a href="#Starting"></a></li>
     18   </ol>
     19 </li>
     20 </ol>
     21 
     22 <h2></h2>
     23 <ol>
     24   <li><a href="http://android-developers.blogspot.com/2010/04/multitasking-android-way.html">
     25 Android </a></li>
     26 </ol>
     27 
     28 <h2></h2>
     29 <ol>
     30   <li><a href="{@docRoot}design/patterns/navigation.html">Android
     31 </a></li>
     32   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}
     33 </a></li>
     34   <li><a href="{@docRoot}guide/components/recents.html"></a></li>
     35 </ol>
     36 </div>
     37 </div>
     38 
     39 
     40 <p><a href="{@docRoot}guide/components/activities.html">Activity</a> Activity  Activity
     41 
     42  Activity  Activity 
     43 </p>
     44 
     45 <p> Activity  Activity Intent 
     46 
     47 
     48  Intent  Activity Intent
     49 Activity Activity 
     50  Intent ActivityActivity  Activity 
     51  Activity 
     52 Android  Activity <em></em>
     53 </p>
     54 
     55 <p> Activity
     56  Activity <em></em>
     57 </p>
     58 
     59 <!-- SAVE FOR WHEN THE FRAGMENT DOC IS ADDED
     60 <div class="sidebox-wrapper">
     61 <div class="sidebox">
     62 <h3>Adding fragments to a task's back stack</h3>
     63 
     64 <p>Your activity can also include {@link android.app.Fragment}s to the back stack. For example,
     65 suppose you have a two-pane layout using fragments, one of which is a list view (fragment A) and the
     66 other being a layout to display an item from the list (fragment B). When the user selects an item
     67 from the list, fragment B is replaced by a new fragment (fragment C). In this case, it might be
     68 desireable for the user to navigate back to reveal fragment B, using the <em>Back</em> button.</p>
     69 <p>In order to add fragment B to the back stack so that this is possible, you must call {@link
     70 android.app.FragmentTransaction#addToBackStack addToBackStack()} before you {@link
     71 android.app.FragmentTransaction#commit()} the transaction that replaces fragment B with fragment
     72 C.</p>
     73 <p>For more information about using fragments and adding them to the back stack, see the {@link
     74 android.app.Fragment} class documentation.</p>
     75 
     76 </div>
     77 </div>
     78 -->
     79 
     80 <p>
     81 
     82 Activity  Activity 
     83 
     84  </p>
     85 
     86 <p> Activity  Activity  Activity 
     87  Activity Activity 
     88  Activity Activity  Activity  UI <em></em>
     89 
     90 
     91  Activity  Activity <em></em>
     92 
     93 
     94 
     95  1  Activity 
     96 
     97 </p>
     98 
     99 <img src="{@docRoot}images/fundamentals/diagram_backstack.png" alt="" />
    100 <p class="img-caption"><strong> 1. </strong> Activity 
    101  Activity  Activity <em></em>
    102 
    103 </p>
    104 
    105 
    106 <p> Activity  Activity Activity<em></em>
    107 
    108 
    109  Activity </p>
    110 
    111 <div class="figure" style="width:287px">
    112 <img src="{@docRoot}images/fundamentals/diagram_multitasking.png" alt="" /> <p
    113 class="img-caption"><strong> 2. </strong> B
    114  A </p>
    115 </div>
    116 <div class="figure" style="width:215px">
    117   <img src="{@docRoot}images/fundamentals/diagram_multiple_instances.png" alt="" /> <p
    118 class="img-caption"><strong> 3. </strong> Activity </p>
    119 </div>
    120 
    121 <p><em></em>
    122  Activity  2 
    123 
    124 
    125 
    126  A Activity Activity  Activity
    127 <em></em>
    128 
    129  A
    130  Activity 
    131 B A  A  Activity  Activity 
    132 
    133 
    134 
    135 <a href="{@docRoot}guide/components/recents.html"></a> B Android 
    136 
    137 
    138 
    139 </p>
    140 
    141 <p class="note"><strong></strong> Activity Activity <a href="#ActivityState"> Activity </a>
    142 
    143 
    144 </p>
    145 
    146 <p> Activity  Activity  Activity Activity  Activity 
    147 
    148 
    149  Activity  Activity  3 
    150  Activity  UI <em></em>
    151 
    152 
    153  Activity 
    154 <a href="#ManagingTasks"></a></p>
    155 
    156 
    157 <p>Activity </p>
    158 
    159 <ul>
    160   <li> Activity A  Activity B Activity A  Activity B  Activity A <em></em>
    161 
    162 
    163 </li>
    164   <li> Activity <em></em>
    165 
    166  Activity  Activity
    167 
    168 </li>
    169   <li> Activity <em></em>
    170 
    171  Activity  Activity  Activity <em></em>
    172 </li>
    173   <li>Activity </li>
    174 </ul>
    175 
    176 
    177 <div class="note design">
    178 <p><strong></strong></p>
    179   <p> Android  Android <a href="{@docRoot}design/patterns/navigation.html"></a></p>
    180 </div>
    181 
    182 
    183 <h2 id="ActivityState"> Activity </h2>
    184 
    185 <p> Activity 
    186  Activity 
    187  Activity <strong></strong> Activity 
    188 
    189 </p>
    190 
    191 <p> Activity  Activity  Activity
    192 
    193  Activity  Activity  Activity  Activity Activity
    194 
    195 
    196  Activity 
    197 {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()}
    198 
    199 </p>
    200 
    201 <p> Activity <a href="{@docRoot}guide/components/activities.html#SavingActivityState">Activity</a>
    202 </p>
    203 
    204 
    205 
    206 <h2 id="ManagingTasks"></h2>
    207 
    208 <p>Android  Activity  Activity 
    209 
    210 
    211 
    212  Activity  Activity  Activity  Activity
    213 
    214 
    215 
    216 </p>
    217 
    218 <p> <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}</a>  {@link android.app.Activity#startActivity startActivity()}
    219  Intent 
    220 
    221 </p>
    222 
    223 <p> <a href="{@docRoot}guide/topics/manifest/activity-element.html">
    224 {@code &lt;activity&gt;}</a> </p>
    225 
    226 <ul class="nolist">
    227   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">
    228   {@code taskAffinity}</a></li>
    229   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">
    230   {@code launchMode}</a></li>
    231   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">
    232   {@code allowTaskReparenting}</a></li>
    233   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#clear">
    234   {@code clearTaskOnLaunch}</a></li>
    235   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#always">
    236   {@code alwaysRetainTaskState}</a></li>
    237   <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#finish">
    238   {@code finishOnTaskLaunch}</a></li>
    239 </ul>
    240 
    241 <p> Intent </p>
    242 
    243 <ul class="nolist">
    244   <li>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</li>
    245   <li>{@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}</li>
    246   <li>{@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}</li>
    247 </ul>
    248 
    249 <p> Intent
    250  Activity  Activity </p>
    251 
    252 <p> Activity 
    253 <a href="{@docRoot}guide/components/recents.html"></a>
    254  Activity 
    255 </p>
    256 
    257 <p class="caution"><strong></strong> Activity 
    258  Activity  Activity  Activity  Activity <em></em>
    259 
    260 
    261 </p>
    262 
    263 
    264 <h3 id="TaskLaunchModes"></h3>
    265 
    266 <p> Activity 
    267 </p>
    268 <ul class="nolist">
    269   <li><a href="#ManifestForTasks"></a>
    270     <p> Activity  Activity 
    271 </li>
    272   <li><a href="#IntentFlagsForTasks"> Intent </a>
    273     <p> {@link android.app.Activity#startActivity startActivity()}
    274  {@link android.content.Intent}
    275  Activity </p></li>
    276 </ul>
    277 
    278 <p> Activity
    279 A  Activity B Activity B  Activity A  Activity B
    280  Activity  Activity B
    281  Activity A  Intent  Activity
    282 B </p>
    283 
    284 <p class="note"><strong></strong>
    285  Intent  Intent
    286 </p>
    287 
    288 
    289 <h4 id="ManifestForTasks"></h4>
    290 
    291 <p> Activity  <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}</a>
    292  <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code
    293 launchMode}</a>
    294  Activity </p>
    295 
    296 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code
    297 launchMode}</a>
    298  Activity 
    299 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">launchMode</a></code>
    300 </p>
    301 
    302 <dl>
    303 <dt>{@code "standard"}</dt>
    304   <dd> Activity  Activity 
    305  IntentActivity 
    306 </dd>
    307 <dt>{@code "singleTop"}</dt>
    308   <dd> Activity 
    309 {@link
    310 android.app.Activity#onNewIntent onNewIntent()}
    311  Intent Activity Activity  Activity  Activity <em></em>
    312 
    313 
    314   <p> Activity A  Activity BC
    315  D A-B-C-DD  D  Activity  Intent D
    316  {@code "standard"}  A-B-C-D-D D  {@code "singleTop"} D
    317  {@link
    318 android.app.Activity#onNewIntent onNewIntent()}  Intent
    319 A-B-C-D A  Activity  Intent B  {@code "singleTop"} 
    320 
    321 </p>
    322   <p class="note"><strong></strong> Activity  Activity<em></em>
    323  Activity 
    324  Intent  Intent 
    325 {@link android.app.Activity#onNewIntent
    326 onNewIntent()}
    327 <em></em> Activity 
    328 </p>
    329 </dd>
    330 
    331 <dt>{@code "singleTask"}</dt>
    332   <dd> Activity Activity  {@link
    333 android.app.Activity#onNewIntent
    334 onNewIntent()} 
    335  Intent Activity 
    336 
    337   <p class="note"><strong></strong> Activity <em></em> Activity
    338 </p></dd>
    339 <dt>{@code "singleInstance"}</dt>
    340   <dd>
    341 {@code "singleTask"}  Activity  Activity  Activity  Activity 
    342 </dd>
    343 </dl>
    344 
    345 
    346 <p>Android 
    347  Web  Activity  <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}</a>  {@code singleTask}
    348 
    349 Android 
    350  Intent Activity <em></em>
    351 
    352  Intent</p>
    353 
    354 <p> Activity  Activity <em></em> Activity
    355 
    356 {@code singleTask}
    357  Activity Activity  Activity
    358 
    359  4 </p>
    360 
    361 <img src="{@docRoot}images/fundamentals/diagram_backstack_singletask_multiactivity.png" alt="" />
    362 <p class="img-caption"><strong> 4. </strong>singleTask Activity 
    363  Activity 
    364 
    365 </p>
    366 
    367 <p>
    368 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
    369  {@code launchMode}
    370 </p>
    371 
    372 <p class="note"><strong></strong> <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a>
    373  Activity  Intent
    374  Activity </p>
    375 
    376 
    377 
    378 <h4 id="#IntentFlagsForTasks"> Intent </h4>
    379 
    380 <p> Activity  {@link
    381 android.app.Activity#startActivity startActivity()}  Intent
    382  Activity 
    383 </p>
    384 
    385 <p>
    386   <dt>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</dt>
    387     <dd> Activity Activity  Activity 
    388 {@link android.app.Activity#onNewIntent onNewIntent()} 
    389  Intent
    390     <p> {@code "singleTask"} <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a>
    391 </p></dd>
    392   <dt>{@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}</dt>
    393     <dd> Activity  Activity
    394  {@link android.app.Activity#onNewIntent onNewIntent()}
    395  Activity 
    396     <p> {@code "singleTop"} <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a>
    397 </p></dd>
    398   <dt>{@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}</dt>
    399     <dd> Activity  Activity {@link android.app.Activity#onNewIntent onNewIntent()}
    400  Intent  Activity  Activity 
    401 
    402 
    403     <p> <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a>
    404 </p>
    405     <p>{@code FLAG_ACTIVITY_CLEAR_TOP} 
    406 {@code FLAG_ACTIVITY_NEW_TASK}
    407  Activity Intent
    408  </p>
    409     <p class="note"><strong></strong> Activity 
    410 {@code "standard"} Activity  Intent
    411 
    412  {@code "standard"}
    413  Intent  </p>
    414 </dd>
    415 </dl>
    416 
    417 
    418 
    419 
    420 
    421 <h3 id="Affinities"></h3>
    422 
    423 <p> Activity <em></em> Activity 
    424  Activity 
    425  Activity 
    426  Activity  Activity 
    427 
    428 </p>
    429 
    430 <p> <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}</a>
    431 
    432 <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a>  Activity </p>
    433 
    434 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a>
    435 
    436 <a href="{@docRoot}guide/topics/manifest/manifest-element.html">
    437 {@code &lt;manifest&gt;}
    438 </a>
    439 </p>
    440 
    441 <p></p>
    442 <ul>
    443   <li> Activity  Intent 
    444 {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}
    445 
    446 
    447 <p> Activity 
    448 {@link android.app.Activity#startActivity startActivity()}  Activity 
    449 
    450 {@link android.app.Activity#startActivity startActivity()}
    451  Intent  {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}
    452  Activity
    453  Activity  Activity 
    454 </p>
    455 
    456 <p> Activity <em></em>
    457 
    458  Activity Activity
    459 {@code FLAG_ACTIVITY_NEW_TASK} 
    460 {@link android.app.Activity#startActivity startActivity()}
    461  Intent  Activity  Activity 
    462 {@link android.content.Intent#CATEGORY_LAUNCHER}
    463  Intent <a href="#Starting"></a>
    464 
    465 </p>
    466 </li>
    467 
    468   <li>Activity <a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">
    469 {@code allowTaskReparenting}</a>  {@code "true"}
    470   <p>Activity 
    471 </p>
    472   <p> Activity 
    473  Activity  Activity  Activity  Activity 
    474 
    475 
    476  Activity 
    477 </p>
    478 </li>
    479 </ul>
    480 
    481 <p class="note"><strong></strong> {@code .apk}
    482  <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a>
    483  Activity</p>
    484 
    485 
    486 
    487 <h3 id="Clearing"></h3>
    488 
    489 <p> Activity 
    490  Activity
    491 
    492  </p>
    493 
    494 <p> Activity  </p>
    495 
    496 <dl>
    497 <dt><code><a
    498 href="{@docRoot}guide/topics/manifest/activity-element.html#always">alwaysRetainTaskState</a></code>
    499 </dt>
    500 <dd> Activity  {@code "true"} Activity 
    501 
    502 </dd>
    503 
    504 <dt><code><a
    505 href="{@docRoot}guide/topics/manifest/activity-element.html#clear">clearTaskOnLaunch</a></code></dt>
    506 <dd> Activity  {@code "true"} Activity
    507 
    508 <a href="{@docRoot}guide/topics/manifest/activity-element.html#always">
    509 {@code alwaysRetainTaskState}</a> 
    510 
    511 </dd>
    512 
    513 <dt><code><a
    514 href="{@docRoot}guide/topics/manifest/activity-element.html#finish">finishOnTaskLaunch</a></code>
    515 </dt>
    516 <dd>
    517 <a href="{@docRoot}guide/topics/manifest/activity-element.html#clear">{@code clearTaskOnLaunch}</a> Activity 
    518  Activity  Activity
    519  {@code "true"}
    520 Activity 
    521 </dd>
    522 </dl>
    523 
    524 
    525 
    526 
    527 <h3 id="Starting"></h3>
    528 
    529 <p> Activity  {@code "android.intent.action.MAIN"}
    530 {@code "android.intent.category.LAUNCHER"}
    531  Intent 
    532 </p>
    533 
    534 <pre>
    535 &lt;activity ... &gt;
    536     &lt;intent-filter ... &gt;
    537         &lt;action android:name="android.intent.action.MAIN" /&gt;
    538         &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
    539     &lt;/intent-filter&gt;
    540     ...
    541 &lt;/activity&gt;
    542 </pre>
    543 
    544 <p> Intent  Activity  Activity 
    545 
    546 
    547 </p>
    548 
    549 <p> Activity 
    550  Activity 
    551 {@link android.content.Intent#ACTION_MAIN}
    552  {@link android.content.Intent#CATEGORY_LAUNCHER}
    553  Activity <a href="#LaunchModes"></a> {@code "singleTask"} 
    554 {@code "singleInstance"}
    555  Intent  {@code "singleTask"}
    556 Activity<em></em>
    557 
    558 </p>
    559 
    560 <p> Activity
    561 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
    562 
    563 <a href="{@docRoot}guide/topics/manifest/activity-element.html#finish">{@code finishOnTaskLaunch}</a>
    564  {@code "true"}<a href="#Clearing"></a></p>
    565 
    566 <p> Activity <a href="{@docRoot}guide/components/recents.html"></a>
    567 
    568 </p>
    569 
    570 <!--
    571 <h2>Beginner's Path</h2>
    572 
    573 <p>For more information about how to use intents to
    574 activate other application components and publish the intents to which your components
    575 respond, continue with the <b><a
    576 href="{@docRoot}guide/components/intents-filters.html">Intents and Intent
    577 Filters</a></b> document.</p>
    578 -->
    579