1 page.title= 2 parent.title= 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"></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">Multitasking the Android Way</a> 25 </li> 26 </ol> 27 28 <h2></h2> 29 <ol> 30 <li><a href="{@docRoot}design/patterns/navigation.html">Android Design: Navigation</a> 31 </li> 32 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>} manifest element</a> 33 </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"></a> 41 42 1 43 </p> 44 45 <p> 46 47 48 49 50 51 Android <em></em> 52 53 </p> 54 55 <p> 56 <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 83 84 </p> 85 86 <p> 87 88 [<em></em>] UI 89 90 91 — [<em></em>] 92 93 94 95 1 96 97 </p> 98 99 <img src="{@docRoot}images/fundamentals/diagram_backstack.png" alt="" /> 100 <p class="img-caption"><strong> 1.</strong> 101 [<em></em>] 102 103 </p> 104 105 106 <p> [<em></em>] 107 108 109 </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> 2 : 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> 1 </p> 119 </div> 120 121 <p> [<em></em>] 122 — 2 123 124 125 126 A 3 2 127 [<em></em>] 128 129 A 130 B B 131 A A — 3 132 133 134 135 B <a href="{@docRoot}guide/components/recents.html"></a> B Android 136 137 138 139 </p> 140 141 <p class="note"><strong>:</strong> <a href="#ActivityState"></a> 142 143 144 </p> 145 146 <p> 147 148 149 3 1 150 [<em></em>] UI 151 152 153 1 154 <a href="#ManagingTasks"></a></p> 155 156 157 <p></p> 158 159 <ul> 160 <li> A B A B [<em></em>] A 161 162 163 </li> 164 <li> [<em></em>] 165 166 167 168 </li> 169 <li> [<em></em>] 170 171 <em></em> 172 </li> 173 <li></li> 174 </ul> 175 176 177 <div class="note design"> 178 <p><strong> </strong></p> 179 <p>Android Android Design <a href="{@docRoot}design/patterns/navigation.html">Navigation</a></p> 180 </div> 181 182 183 <h2 id="ActivityState"></h2> 184 185 <p> 186 187 <strong></strong> 188 189 </p> 190 191 <p> 1 192 193 194 195 196 {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} 197 198 199 </p> 200 201 <p><a href="{@docRoot}guide/components/activities.html#SavingActivityState">Activities</a> 202 </p> 203 204 205 206 <h2 id="ManagingTasks"></h2> 207 208 <p>Android 209 210 211 212 213 214 215 216 </p> 217 218 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> {@link android.app.Activity#startActivity startActivity()} 219 220 221 </p> 222 223 <p> <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> 224 </p> 225 226 <ul class="nolist"> 227 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#aff"> {@code taskAffinity}</a> 228 </li> 229 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode"> {@code launchMode}</a> 230 </li> 231 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent"> {@code allowTaskReparenting}</a> 232 </li> 233 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#clear"> {@code clearTaskOnLaunch}</a> 234 </li> 235 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#always"> {@code alwaysRetainTaskState}</a> 236 </li> 237 <li><a href="{@docRoot}guide/topics/manifest/activity-element.html#finish"> {@code finishOnTaskLaunch}</a> 238 </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> 250 </p> 251 252 <p> 253 <a href="{@docRoot}guide/components/recents.html"></a> 254 255 </p> 256 257 <p class="caution"><strong>:</strong> 258 [<em></em>] 259 260 261 </p> 262 263 264 <h3 id="TaskLaunchModes"></h3> 265 266 <p> 267 2 </p> 268 <ul class="nolist"> 269 <li><a href="#ManifestForTasks"> </a> 270 <p> 271 </li> 272 <li><a href="#IntentFlagsForTasks"> </a> 273 <p>{@link android.app.Activity#startActivity startActivity()} {@link android.content.Intent} 274 275 </p></li> 276 </ul> 277 278 <p> A B B A B 279 280 B B A 281 282 </p> 283 284 <p class="note"><strong>:</strong> 285 286 </p> 287 288 289 <h4 id="ManifestForTasks"> </h4> 290 291 <p> <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a> 292 293 294 </p> 295 296 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code launchMode}</a> 297 298 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">launchMode</a></code> 4 299 300 </p> 301 302 <dl> 303 <dt>{@code "standard"}</dt> 304 <dd> 305 1 306 </dd> 307 <dt>{@code "singleTop"}</dt> 308 <dd>{@link android.app.Activity#onNewIntent onNewIntent()} 309 310 311 1 <em></em> 312 313 314 <p> BC D A A-B-C-D D 315 D D {@code "standard"} A-B-C-D-D D {@code "singleTop"} D {@link android.app.Activity#onNewIntent onNewIntent()} — A-B-C-D B {@code "singleTop"} B 316 317 318 319 320 321 </p> 322 <p class="note"><strong>:</strong> [<em></em>] 323 {@link android.app.Activity#onNewIntent onNewIntent()} [<em></em>] 324 325 326 327 328 </p> 329 </dd> 330 331 <dt>{@code "singleTask"}</dt> 332 <dd>{@link android.app.Activity#onNewIntent onNewIntent()} 333 334 335 1 336 337 <p class="note"><strong>:</strong> [<em></em>] 338 </p></dd> 339 <dt>{@code "singleInstance"}</dt> 340 <dd> {@code "singleTask"} 341 342 </dd> 343 </dl> 344 345 346 <p>Android Browser <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> {@code singleTask} Android Browser <em></em> 347 348 349 350 Android Browser Android Browser 351 352 </p> 353 354 <p> [<em></em>] 355 {@code singleTask} 356 357 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 363 364 365 </p> 366 367 <p> <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></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> 373 374 </p> 375 376 377 378 <h4 id="#IntentFlagsForTasks"> </h4> 379 380 <p>{@link android.app.Activity#startActivity startActivity()} 381 382 383 </p> 384 385 <p> 386 <dt>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</dt> 387 <dd> {@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> {@link android.app.Activity#onNewIntent onNewIntent()} 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>{@link android.app.Activity#onNewIntent onNewIntent()} 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 407 408 </p> 409 <p class="note"><strong>:</strong> {@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> 424 425 426 427 428 </p> 429 430 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a> 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">{@code <manifest>}</a> 435 436 437 438 439 </p> 440 441 <p> 2 </p> 442 <ul> 443 <li> {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} 444 445 446 447 <p>{@link android.app.Activity#startActivity startActivity()} 448 449 {@link android.app.Activity#startActivity startActivity()} {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} 450 451 452 453 454 </p> 455 456 <p> [<em></em>] 457 458 {@link android.app.Activity#startActivity startActivity()} {@code FLAG_ACTIVITY_NEW_TASK} {@link android.content.Intent#CATEGORY_LAUNCHER} <a href="#Starting"></a> 459 460 461 462 463 464 465 </p> 466 </li> 467 468 <li> <a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">{@code allowTaskReparenting}</a> {@code "true"} 469 470 <p> 471 </p> 472 <p> 473 474 475 476 477 </p> 478 </li> 479 </ul> 480 481 <p class="note"><strong>:</strong> {@code .apk} 1 <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a> 482 483 </p> 484 485 486 487 <h3 id="Clearing"></h3> 488 489 <p> 490 491 492 </p> 493 494 <p> </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> {@code "true"} 501 502 </dd> 503 504 <dt><code><a 505 href="{@docRoot}guide/topics/manifest/activity-element.html#clear">clearTaskOnLaunch</a></code></dt> 506 <dd> {@code "true"} 507 508 <a href="{@docRoot}guide/topics/manifest/activity-element.html#always">{@code alwaysRetainTaskState}</a> 509 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><a href="{@docRoot}guide/topics/manifest/activity-element.html#clear">{@code clearTaskOnLaunch}</a> 1 517 518 519 {@code "true"} 520 521 </dd> 522 </dl> 523 524 525 526 527 <h3 id="Starting"></h3> 528 529 <p> {@code "android.intent.action.MAIN"} {@code "android.intent.category.LAUNCHER"} 530 531 532 </p> 533 534 <pre> 535 <activity ... > 536 <intent-filter ... > 537 <action android:name="android.intent.action.MAIN" /> 538 <category android:name="android.intent.category.LAUNCHER" /> 539 </intent-filter> 540 ... 541 </activity> 542 </pre> 543 544 <p> 545 546 547 </p> 548 549 <p> 2 550 {@link android.content.Intent#ACTION_MAIN} {@link android.content.Intent#CATEGORY_LAUNCHER} {@code "singleTask"} {@code "singleInstance"} 2 <a href="#LaunchModes"></a> 551 552 553 554 555 {@code "singleTask"} 556 [<em></em>] 557 558 </p> 559 560 <p><code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#finish">{@code finishOnTaskLaunch}</a> {@code "true"} <a href="#Clearing"></a> 561 562 563 564 </p> 565 566 <p><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