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">  Android 
     25 </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
     43  Activity </p>
     44 
     45 <p>Activity  Activity
     46 
     47  Activity 
     48 Activity ( Activity  Activity)
     49 
     50  Activity  Activity 
     51  Activity  Android  Activity 
     52 
     53 <em></em></p>
     54 
     55 <p> Activity 
     56 Activity  (<em></em>)  Activity 
     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  [] <em></em> Activity  (Activity ) Activity ( UI )
     89 
     90 
     91  Activity  &mdash;  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> []<em></em> Activity  Activity ( Activity)
    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  A 
    114 </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  &mdash;  2 
    123 
    124 
    125 
    126  ( A)  Activity &mdash;  Activity 
    127  [] <em></em>
    128 
    129  A 
    130  ( B) Activity 
    131  A  A  &mdash;  Activity  Activity 
    132 
    133 
    134 
    135  B (<a href="{@docRoot}guide/components/recents.html"></a>) Android 
    136 
    137 
    138 
    139 </p>
    140 
    141 <p class="note"><strong></strong>
    142  Activity  Activity 
    143  <a href="#ActivityState">Activity </a>
    144 </p>
    145 
    146 <p> Activity  Activity  Activity Activity  ( Activity )
    147 
    148 
    149  Activity  () 3 
    150  [] Activity <em></em> ( UI )
    151 
    152 
    153  Activity 
    154 <a href="#ManagingTasks"></a></p>
    155 
    156 
    157 <p> Activity </p>
    158 
    159 <ul>
    160   <li> Activity A  Activity BActivity A ()
    161 
    162  Activity B  [] <em></em>Activity A 
    163 </li>
    164   <li> [] <em></em> Activity 
    165 
    166  Activity  Activity
    167 
    168 </li>
    169   <li> [] <em></em> Activity 
    170 
    171  Activity Activity  Activity 
    172 <em></em></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  Activity 
    186  Activity 
    187  &mdash; <strong></strong> &mdash;  Activity  Activity 
    188 
    189 </p>
    190 
    191 <p> Activity ( Activity ) Activity
    192 
    193  Activity  Activity  Activity  Activity ()
    194 
    195 
    196  Activity  {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} 
    197 
    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  &mdash;  Activity  &mdash;  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 
    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></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> Activity 
    250 </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"></a>
    273     <p> {@link android.app.Activity#startActivity startActivity()}  {@link android.content.Intent}  Activity  () 
    274 
    275 </p></li>
    276 </ul>
    277 
    278 <p> Activity A  Activity BActivity B  ()  Activity A  Activity B 
    279 
    280  Activity  Activity B  Activity B  () Activity A  ()
    281 
    282 </p>
    283 
    284 <p class="note"><strong></strong>
    285 
    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>  <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code
    292 launchMode}</a>  Activity 
    293 
    294 </p>
    295 
    296 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code
    297 launchMode}</a>  Activity 
    298 
    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 
    305 Activity 
    306 </dd>
    307 <dt>{@code "singleTop"}</dt>
    308   <dd> Activity  {@link
    309 android.app.Activity#onNewIntent onNewIntent()}  Activity 
    310 
    311 Activity  ( Activity  Activity <em></em>)
    312 
    313 
    314   <p> Activity A  Activity BC  D ( A-B-C-DD )
    315  D Activity 
    316  D  {@code "standard"}  A-B-C-D-D D  {@code "singleTop"}D  {@link
    317 android.app.Activity#onNewIntent onNewIntent()}  &mdash;  A-B-C-D B Activity  B  {@code "singleTop"} 
    318 
    319 
    320 
    321 </p>
    322   <p class="note"><strong></strong> Activity  []<em></em>  Activity
    323  Activity  []<em></em>  {@link android.app.Activity#onNewIntent
    324 onNewIntent()}  Activity 
    325 
    326 
    327 
    328 </p>
    329 </dd>
    330 
    331 <dt>{@code "singleTask"}</dt>
    332   <dd> Activity  Activity  {@link
    333 android.app.Activity#onNewIntent onNewIntent()} 
    334 
    335  Activity 
    336 
    337   <p class="note"><strong></strong> Activity  []  Activity
    338 <em></em></p></dd>
    339 <dt>{@code "singleInstance"}</dt>
    340   <dd> {@code "singleTask"}  Activity 
    341 Activity  Activity 
    342 </dd>
    343 </dl>
    344 
    345 
    346 <p>Android  Activity  &mdash;  <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}</a>  {@code singleTask} 
    347  Android  Activity <em></em>
    348 
    349 
    350 
    351 
    352 </p>
    353 
    354 <p> Activity  Activity  Activity  []  Activity<em></em>
    355  {@code singleTask}  Activity Activity 
    356 
    357  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> <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>  {@code launchMode} 
    368 
    369 
    370 </p>
    371 
    372 <p class="note"><strong></strong> <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a>  Activity  Activity 
    373 
    374 </p>
    375 
    376 
    377 
    378 <h4 id="#IntentFlagsForTasks"></h4>
    379 
    380 <p> Activity  {@link
    381 android.app.Activity#startActivity startActivity()}  Activity 
    382 
    383 </p>
    384 
    385 <p>
    386   <dt>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</dt>
    387     <dd> Activity Activity  Activity  {@link android.app.Activity#onNewIntent onNewIntent()} 
    388 
    389 
    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 () {@link android.app.Activity#onNewIntent onNewIntent()}  Activity 
    394 
    395 
    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  Activity {@link android.app.Activity#onNewIntent onNewIntent()}  Activity  ()
    400 
    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}  {@code FLAG_ACTIVITY_NEW_TASK} 
    406  Activity
    407 
    408  </p>
    409     <p class="note"><strong></strong> Activity  {@code "standard"}
    410 
    411 
    412  {@code "standard"} 
    413  </p>
    414 </dd>
    415 </dl>
    416 
    417 
    418 
    419 
    420 
    421 <h3 id="Affinities"></h3>
    422 
    423 <p><em></em> Activity  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>  <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a>  Activity 
    431 
    432 </p>
    433 
    434 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a>  <a href="{@docRoot}guide/topics/manifest/manifest-element.html">
    435 {@code &lt;manifest&gt;}</a> 
    436 
    437 
    438 
    439 </p>
    440 
    441 <p></p>
    442 <ul>
    443   <li> Activity 
    444 {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} 
    445 
    446 
    447 <p> Activity  Activity ( {@link android.app.Activity#startActivity startActivity()}) 
    448 
    449 
    450 {@link android.app.Activity#startActivity startActivity()}  {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}  Activity
    451 
    452 
    453  Activity Activity 
    454 </p>
    455 
    456 <p> Activity  [] <em></em>
    457 
    458  ()  Activity {@code FLAG_ACTIVITY_NEW_TASK} 
    459 {@link android.app.Activity#startActivity startActivity()} 
    460 
    461  Activity  ( Activity  {@link android.content.Intent#CATEGORY_LAUNCHER} <a href="#Starting"></a>)
    462 
    463 
    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  ()
    474  Activity  Activity Activity 
    475 
    476  Activity 
    477 </p>
    478 </li>
    479 </ul>
    480 
    481 <p class="note"><strong></strong> {@code .apk}  <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a>  Activity 
    482 
    483 </p>
    484 
    485 
    486 
    487 <h3 id="Clearing"></h3>
    488 
    489 <p> Activity  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"}
    501  Activity
    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"}
    507  Activity
    508 
    509 <a href="{@docRoot}guide/topics/manifest/activity-element.html#always">
    510 {@code alwaysRetainTaskState}</a> 
    511 </dd>
    512 
    513 <dt><code><a
    514 href="{@docRoot}guide/topics/manifest/activity-element.html#finish">finishOnTaskLaunch</a></code>
    515 </dt>
    516 <dd> <a href="{@docRoot}guide/topics/manifest/activity-element.html#clear">{@code clearTaskOnLaunch}</a>  Activity 
    517 
    518  Activity  Activity
    519  {@code "true"}Activity 
    520 
    521 </dd>
    522 </dl>
    523 
    524 
    525 
    526 
    527 <h3 id="Starting"></h3>
    528 
    529 <p> Activity 
    530 {@code "android.intent.action.MAIN"} 
    531 {@code "android.intent.category.LAUNCHER"}  Activity 
    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> Activity  Activity  Activity 
    545 
    546 
    547 </p>
    548 
    549 <p> Activity 
    550  Activity <a href="#LaunchModes"></a> {@code "singleTask"} 
    551 {@code "singleInstance"} Activity  {@link android.content.Intent#ACTION_MAIN}  {@link android.content.Intent#CATEGORY_LAUNCHER} 
    552 
    553 
    554 
    555  {@code "singleTask"} Activity
    556  []<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 <a href="{@docRoot}guide/topics/manifest/activity-element.html#finish">{@code finishOnTaskLaunch}</a>  {@code "true"} (<a href="#Clearing"></a>)
    563 
    564 </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