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"> 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 <activity>} 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"></a> . 41 42 . . 43 , .</p> 44 45 <p> . 46 , "" 47 . 48 . , 49 "" ( 50 , ). 51 . 52 , Android 53 <em></em> .</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 . 89 <em></em> 90 , ( ) 91 ( UI ). 92 . . , 93 , <em></em> . , 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> : 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> .</p> 119 </div> 120 121 <p> "" 122 <em></em> . 123 124 , . 125 ( 2 ). "" 126 . ( A) 127 . <em></em> 128 129 . A 130 . 131 ( B) . 132 , A 133 . A . 134 , 135 . 136 B . 137 ( 138 <a href="{@docRoot}guide/components/recents.html"> </a> ). 139 Android .</p> 140 141 <p class="note"><strong>:</strong> . 142 , 143 , . 144 <a href="#ActivityState"> </a> .</p> 145 146 <p> , 147 , 148 ( 149 ). , 150 ( ), 3. 151 <em></em> , 152 ( 153 UI ). , 154 . <a href="#ManagingTasks"> </a> .</p> 155 156 157 <p> .</p> 158 159 <ul> 160 <li> A B A , 161 (: ) . 162 B <em></em> A 163 .</li> 164 <li> <em></em> 165 166 . . 167 , 168 .</li> 169 <li> <em></em> , 170 . 171 . , 172 <em>.</em></li> 173 <li> , .</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"> </h2> 184 185 <p> , 186 . , 187 . <strong> .</strong> 188 , 189 .</p> 190 191 <p> ( 192 ), 193 . , . , 194 195 . 196 ( ) . 197 . 198 {@link android.app.Activity#onSaveInstanceState onSaveInstanceState()} 199 .</p> 200 201 <p> <a href="{@docRoot}guide/components/activities.html#SavingActivityState"></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> 219 <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> 220 , 221 {@link android.app.Activity#startActivity startActivity()} .</p> 222 223 <p> , <a href="{@docRoot}guide/topics/manifest/activity-element.html"> 224 {@code <activity>}</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> 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 . 259 , . 260 <em></em> . 261 .</p> 262 263 264 <h3 id="TaskLaunchModes"> </h3> 265 266 <p> 267 . .</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()} 274 {@link android.content.Intent} ( 275 ) .</p></li> 276 </ul> 277 278 <p>, A B B 279 ( ) A 280 B . B 281 , A ( ) B 282 ( ) .</p> 283 284 <p class="note"><strong>:</strong> 285 , 286 .</p> 287 288 289 <h4 id="ManifestForTasks"> </h4> 290 291 <p> , 292 <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> 293 <a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code 294 launchMode}</a> .</p> 295 296 <p><a href="{@docRoot}guide/topics/manifest/activity-element.html#lmode">{@code 297 launchMode}</a> 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>. 305 . , 306 .</dd> 307 <dt>{@code "singleTop"}</dt> 308 <dd> , 309 . {@link 310 android.app.Activity#onNewIntent onNewIntent()} 311 . , 312 ( 313 <em></em> ). 314 <p> A B, C, D 315 ( A-B-C-D D ). D . 316 D {@code "standard"} , 317 A-B-C-D-D . , D {@code "singleTop"} , D 318 {@link 319 android.app.Activity#onNewIntent onNewIntent()} . . 320 A-B-C-D . B , 321 B {@code "singleTop"} .</p> 322 <p class="note"><strong>:</strong> , 323 <em></em> . 324 325 , <em></em> {@link android.app.Activity#onNewIntent 326 onNewIntent()} 327 328 .</p> 329 </dd> 330 331 <dt>{@code "singleTask"}</dt> 332 <dd> . 333 , , 334 . {@link 335 android.app.Activity#onNewIntent onNewIntent()} . 336 . 337 <p class="note"><strong>:</strong> , 338 <em></em> .</p></dd> 339 <dt>{@code "singleInstance"}.</dt> 340 <dd>{@code "singleTask"} . 341 . . 342 .</dd> 343 </dl> 344 345 346 <p> Android . 347 . <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code <activity>}</a> {@code singleTask} . 348 Android 349 <em></em> 350 . , , 351 352 .</p> 353 354 <p> 355 <em></em> . , 356 {@code singleTask} 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> 368 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></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 . 374 .</p> 375 376 377 378 <h4 id="#IntentFlagsForTasks"> </h4> 379 380 <p> , . 381 {@link 382 android.app.Activity#startActivity startActivity()} . 383 .</p> 384 385 <p> 386 <dt>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</dt> 387 <dd> . , 388 389 {@link android.app.Activity#onNewIntent onNewIntent()} . 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> ( ), 394 {@link android.app.Activity#onNewIntent onNewIntent()} 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> , 400 401 ( ) , 402 {@link android.app.Activity#onNewIntent onNewIntent()} . 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 408 . </p> 409 <p class="note"><strong>:</strong> 410 {@code "standard"} , 411 412 . 413 {@code "standard"} , . </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> 431 <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a> 432 .</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 <manifest>} 438 </a> . 439 .</p> 440 441 <p> .</p> 442 <ul> 443 <li> 444 {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} 445 . 446 447 <p> 448 {@link android.app.Activity#startActivity startActivity()} . 449 . 450 {@link android.app.Activity#startActivity startActivity()} 451 {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} 452 , . . 453 . , 454 . , .</p> 455 456 <p> <em></em> 457 458 , . ( 459 ) . 460 {@code FLAG_ACTIVITY_NEW_TASK} 461 {@link android.app.Activity#startActivity startActivity()} . 462 463 , 464 . ( 465 {@link android.content.Intent#CATEGORY_LAUNCHER} . <a href="#Starting"> </a> ).</p> 466 </li> 467 468 <li> <a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent"> 469 {@code allowTaskReparenting}</a> {@code "true"} . 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} "" 482 , <a href="{@docRoot}guide/topics/manifest/activity-element.html#aff">{@code taskAffinity}</a> 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 . , 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> , 517 518 . 519 . {@code "true"} , 520 . 521 .</dd> 522 </dl> 523 524 525 526 527 <h3 id="Starting"> </h3> 528 529 <p> 530 {@code "android.intent.action.MAIN"} 531 {@code "android.intent.category.LAUNCHER"} 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> . 550 . , <a href="#LaunchModes"> 551 </a> , {@code "singleTask"} 552 {@code "singleInstance"} 553 {@link android.content.Intent#ACTION_MAIN} 554 {@link android.content.Intent#CATEGORY_LAUNCHER} . 555 . {@code "singleTask"} , 556 . <em></em> 557 . . 558 . .</p> 559 560 <p> , 561 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></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> 567 <a href="{@docRoot}guide/components/recents.html"> 568 </a> .</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