1page.title=<activity> 2parent.title=The AndroidManifest.xml File 3parent.link=manifest-intro.html 4@jd:body 5 6<dl class="xml"> 7<dt>syntax:</dt> 8<dd><pre class="stx"><activity android:<a href="#embedded">allowEmbedded</a>=["true" | "false"] 9 android:<a href="#reparent">allowTaskReparenting</a>=["true" | "false"] 10 android:<a href="#always">alwaysRetainTaskState</a>=["true" | "false"] 11 android:<a href="#autoremrecents">autoRemoveFromRecents</a>=["true" | "false"] 12 android:<a href="#clear">clearTaskOnLaunch</a>=["true" | "false"] 13 android:<a href="#config">configChanges</a>=["mcc", "mnc", "locale", 14 "touchscreen", "keyboard", "keyboardHidden", 15 "navigation", "screenLayout", "fontScale", "uiMode", 16 "orientation", "screenSize", "smallestScreenSize"] 17 android:<a href="#dlmode">documentLaunchMode</a>=["intoExisting", "always", 18 "none", "never"] 19 android:<a href="#enabled">enabled</a>=["true" | "false"] 20 android:<a href="#exclude">excludeFromRecents</a>=["true" | "false"] 21 android:<a href="#exported">exported</a>=["true" | "false"] 22 android:<a href="#finish">finishOnTaskLaunch</a>=["true" | "false"] 23 android:<a href="#hwaccel">hardwareAccelerated</a>=["true" | "false"] 24 android:<a href="#icon">icon</a>="<i>drawable resource</i>" 25 android:<a href="#label">label</a>="<i>string resource</i>" 26 android:<a href="#lmode">launchMode</a>=["multiple" | "singleTop" | 27 "singleTask" | "singleInstance"] 28 android:<a href="#maxRecents">maxRecents</a>="<i>integer</i>" 29 android:<a href="#multi">multiprocess</a>=["true" | "false"] 30 android:<a href="#nm">name</a>="<i>string</i>" 31 android:<a href="#nohist">noHistory</a>=["true" | "false"] <!-- ##api level 3## --> 32 android:<a href="#parent">parentActivityName</a>="<i>string</i>" <!-- api level 16 --> 33 android:<a href="#prmsn">permission</a>="<i>string</i>" 34 android:<a href="#proc">process</a>="<i>string</i>" 35 android:<a href="#relinquish">relinquishTaskIdentity</a>=["true" | "false"] 36 android:<a href="#screen">screenOrientation</a>=["unspecified" | "behind" | 37 "landscape" | "portrait" | 38 "reverseLandscape" | "reversePortrait" | 39 "sensorLandscape" | "sensorPortrait" | 40 "userLandscape" | "userPortrait" | 41 "sensor" | "fullSensor" | "nosensor" | 42 "user" | "fullUser" | "locked"] 43 android:<a href="#state">stateNotNeeded</a>=["true" | "false"] 44 android:<a href="#aff">taskAffinity</a>="<i>string</i>" 45 android:<a href="#theme">theme</a>="<i>resource or theme</i>" 46 android:<a href="#uioptions">uiOptions</a>=["none" | "splitActionBarWhenNarrow"] 47 android:<a href="#wsoft">windowSoftInputMode</a>=["stateUnspecified", 48 "stateUnchanged", "stateHidden", 49 "stateAlwaysHidden", "stateVisible", 50 "stateAlwaysVisible", "adjustUnspecified", 51 "adjustResize", "adjustPan"] > <!-- ##api level 3## --> 52 . . . 53</activity></pre></dd> 54 55<dt>contained in:</dt> 56<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code></dd> 57 58<dt>can contain:</dt> 59<dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> 60<br/><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html"><meta-data></a></code></dd> 61 62<dt>description:</dt> 63<dd itemprop="description">Declares an activity (an {@link android.app.Activity} subclass) that 64implements part of the application's visual user interface. All activities 65must be represented by {@code <activity>} 66elements in the manifest file. Any that are not declared there will not be seen 67by the system and will never be run. 68 69<dt>attributes:</dt> 70<dd><dl class="attr"> 71<dt><a name="embedded"></a>{@code android:allowEmbedded}</dt> 72<dd> 73 Indicate that the activity can be launched as the embedded child of another 74 activity. Particularly in the case where the child lives in a container 75 such as a Display owned by another activity. For example, activities 76 that are used for Wear custom notifications must declare this so 77 Wear can display the activity in it's context stream, which resides 78 in another process. 79 80 <p>The default value of this attribute is <code>false</code>. 81</dd> 82<dt><a name="reparent"></a>{@code android:allowTaskReparenting}</dt> 83<dd>Whether or not the activity can move from the task that started it to 84the task it has an affinity for when that task is next brought to the 85front — "{@code true}" if it can move, and "{@code false}" if it 86must remain with the task where it started. 87 88<p> 89If this attribute is not set, the value set by the corresponding 90<code><a href="{@docRoot}guide/topics/manifest/application-element.html#reparent">allowTaskReparenting</a></code> 91attribute of the <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element 92applies to the activity. The default value is "{@code false}". 93</p> 94 95<p> 96Normally when an activity is started, it's associated with the task of 97the activity that started it and it stays there for its entire lifetime. 98You can use this attribute to force it to be re-parented to the task it 99has an affinity for when its current task is no longer displayed. 100Typically, it's used to cause the activities of an application to move 101to the main task associated with that application. 102</p> 103 104<p> 105For example, if an e-mail message contains a link to a web page, clicking 106the link brings up an activity that can display the page. That activity 107is defined by the browser application, but is launched as part of the e-mail 108task. If it's reparented to the browser task, it will be shown when the 109browser next comes to the front, and will be absent when the e-mail task 110again comes forward. 111</p> 112 113<p> 114The affinity of an activity is defined by the 115<code><a href="#aff">taskAffinity</a></code> attribute. The affinity 116of a task is determined by reading the affinity of its root activity. 117Therefore, by definition, a root activity is always in a task with the 118same affinity. Since activities with "{@code singleTask}" or 119"{@code singleInstance}" launch modes can only be at the root of a task, 120re-parenting is limited to the "{@code standard}" and "{@code singleTop}" 121modes. (See also the <code><a href="#lmode">launchMode</a></code> 122attribute.) 123</p></dd> 124 125<dt><a name="always"></a>{@code android:alwaysRetainTaskState}</dt> 126<dd>Whether or not the state of the task that the activity is in will always 127be maintained by the system — "{@code true}" if it will be, and 128"{@code false}" if the system is allowed to reset the task to its initial 129state in certain situations. The default value is "{@code false}". This 130attribute is meaningful only for the root activity of a task; it's ignored 131for all other activities. 132 133<p> 134Normally, the system clears a task (removes all activities from the stack 135above the root activity) in certain situations when the user re-selects that 136task from the home screen. Typically, this is done if the user hasn't visited 137the task for a certain amount of time, such as 30 minutes. 138</p> 139 140<p> 141However, when this attribute is "{@code true}", users will always return 142to the task in its last state, regardless of how they get there. This is 143useful, for example, in an application like the web browser where there is 144a lot of state (such as multiple open tabs) that users would not like to lose. 145</p></dd> 146 147<dt><a name="autoremrecents"></a>{@code android:autoRemoveFromRecents}</dt> 148<dd>Whether or not tasks launched by activities with this attribute remains in the 149<a href="{@docRoot}guide/components/recents.html">overview screen</a> until the last activity in the 150task is completed. If {@code true}, the task is 151automatically removed from the overview screen. This overrides the caller's use of 152{@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}. It must be a boolean value, either 153"{@code true}" or "{@code false}".</dd> 154 155 156<dt><a name="clear"></a>{@code android:clearTaskOnLaunch}</dt> 157<dd>Whether or not all activities will be removed from the task, except for 158the root activity, whenever it is re-launched from the home screen — 159"{@code true}" if the task is always stripped down to its root activity, and 160"{@code false}" if not. The default value is "{@code false}". This attribute 161is meaningful only for activities that start a new task (the root activity); 162it's ignored for all other activities in the task. 163 164<p> 165When the value is "{@code true}", every time users start the task again, they 166are brought to its root activity regardless of what they were last doing in 167the task and regardless of whether they used the <em>Back</em> or <em>Home</em> button to 168leave it. When the value is "{@code false}", the task may be cleared of activities in 169some situations (see the 170<code><a href="#always">alwaysRetainTaskState</a></code> attribute), but not always. 171</p> 172 173<p> 174Suppose, for example, that someone launches activity P from the home screen, 175and from there goes to activity Q. The user next presses <em>Home</em>, and then returns 176to activity P. Normally, the user would see activity Q, since that is what they 177were last doing in P's task. However, if P set this flag to "{@code true}", all 178of the activities on top of it (Q in this case) were removed when the user pressed 179<em>Home</em> and the task went to the background. So the user sees only P when returning 180to the task. 181</p> 182 183<p> 184If this attribute and <code><a href="#reparent">allowTaskReparenting</a></code> 185are both "{@code true}", any activities that can be re-parented are moved to 186the task they share an affinity with; the remaining activities are then dropped, 187as described above. 188</p></dd> 189 190<dt><a name="config"></a>{@code android:configChanges}</dt> 191<dd>Lists configuration changes that the activity will handle itself. When a configuration 192change occurs at runtime, the activity is shut down and restarted by default, but declaring a 193configuration with this attribute will prevent the activity from being restarted. Instead, the 194activity remains running and its <code>{@link android.app.Activity#onConfigurationChanged(android.content.res.Configuration) 195onConfigurationChanged()}</code> method is called. 196 197<p class="note"><strong>Note:</strong> Using this attribute should be 198avoided and used only as a last resort. Please read <a 199href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a> for more 200information about how to properly handle a restart due to a configuration change.</p> 201 202<p> 203Any or all of the following strings are valid values for this attribute. Multiple values are 204separated by '{@code |}' — for example, "{@code locale|navigation|orientation}". 205</p> 206 207<table> 208<tr> 209 <th>Value</th> 210 <th>Description</th> 211</tr><tr> 212 <td>"{@code mcc}"</td> 213 <td>The IMSI mobile country code (MCC) has changed — 214 a SIM has been detected and updated the MCC.</td> 215</tr><tr> 216 <td>"{@code mnc}"</td> 217 <td>The IMSI mobile network code (MNC) has changed — 218 a SIM has been detected and updated the MNC.</td> 219</tr><tr> 220 <td>"{@code locale}"</td> 221 <td>The locale has changed — the user has selected a new 222 language that text should be displayed in.</td> 223</tr><tr> 224 <td>"{@code touchscreen}"</td> 225 <td>The touchscreen has changed. (This should never normally happen.)</td> 226</tr><tr> 227 <td>"{@code keyboard}"</td> 228 <td>The keyboard type has changed — for example, the user has 229 plugged in an external keyboard.</td> 230</tr><tr> 231 <td>"{@code keyboardHidden}"</td> 232 <td>The keyboard accessibility has changed — for example, the 233 user has revealed the hardware keyboard.</td> 234</tr><tr> 235 <td>"{@code navigation}"</td> 236 <td>The navigation type (trackball/dpad) has changed. (This should never normally happen.)</td> 237</tr><tr> 238 <td>"{@code screenLayout}"</td> 239 <td>The screen layout has changed — this might be caused by a 240 different display being activated.</td> 241 </tr><tr> 242 <td>"{@code fontScale}"</td> 243 <td>The font scaling factor has changed — the user has selected 244 a new global font size.</td> 245 </tr><tr> 246 <td>"{@code uiMode}"</td> 247 <td>The user interface mode has changed — this can be caused when the user places the 248device into a desk/car dock or when the night mode changes. See {@link 249android.app.UiModeManager}. 250 <em>Added in API level 8</em>.</td> 251 </tr><tr> 252 <td>"{@code orientation}"</td> 253 <td>The screen orientation has changed — the user has rotated the device. 254 <p class="note"><strong>Note:</strong> If your application targets API level 13 or higher (as 255declared by the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 256minSdkVersion}</a> and <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code 257targetSdkVersion}</a> attributes), then you should also declare the {@code "screenSize"} 258configuration, because it also changes when a device switches between portrait and landscape 259orientations.</p></td> 260 </tr><tr> 261 <td>"{@code screenSize}"</td> 262 <td>The current available screen size has changed. This represents a change in the currently 263available size, relative to the current aspect ratio, so will change when the user switches between 264landscape and portrait. However, if your application targets API level 12 or lower, then your 265activity always handles this configuration change itself (this configuration change does not restart 266your activity, even when running on an Android 3.2 or higher device). 267 <p><em>Added in API level 13.</em></p></td> 268 </tr><tr> 269 <td>"{@code smallestScreenSize}"</td> 270 <td>The physical screen size has changed. This represents a change in size regardless of 271orientation, so will only change when the actual physical screen size has changed such as switching 272to an external display. A change to this configuration corresponds to a change in the <a 273href="{@docRoot}guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier"> 274smallestWidth configuration</a>. However, if your application targets API level 12 or lower, then 275your activity always handles this configuration change itself (this configuration change does not 276restart your activity, even when running on an Android 3.2 or higher device). 277 <p><em>Added in API level 13.</em></p></td> 278 </tr><tr> 279 <td>"{@code layoutDirection}"</td> 280 <td>The layout direction has changed. For example, changing from left-to-right (LTR) 281 to right-to-left (RTL). 282 <em>Added in API level 17.</em></td> 283 </tr> 284</table> 285 286<p> 287All of these configuration changes can impact the resource values seen by the 288application. Therefore, when <code>{@link android.app.Activity#onConfigurationChanged(android.content.res.Configuration) 289onConfigurationChanged()}</code> is called, it will generally be necessary to again 290retrieve all resources (including view layouts, drawables, and so on) to correctly 291handle the change. 292</p></dd> 293 294<dt><a name="dlmode"></a>{@code android:documentLaunchMode}</dt> 295<dd>Specifies how a new instance of an activity should be added to a task each time it is 296launched. This attribute permits the user to have multiple documents from the same application 297appear in the <a href="{@docRoot}guide/components/recents.html">overview screen</a>. 298 299<p>This attribute has four values which produce the following effects when the user opens a document 300with the application:</p> 301 302<table> 303<tr> 304 <th>Value</th> 305 <th>Description</th> 306</tr><tr> 307 <td>"{@code intoExisting}"</td> 308 <td>The activity reuses the existing task for the document. Using this value is the same as setting 309 the {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} flag, <em>without</em> setting the 310 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} flag, as described in 311 <a href="{@docRoot}guide/components/recents.html#flag-new-doc">Using the Intent flag to add a task 312 </a>.</td> 313</tr><tr> 314 <td>"{@code always}"</td> 315 <td>The activity creates a new task for the document, even if the document is already opened. 316 This is the same as setting both the {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} 317 and {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} flags.</td> 318</tr><tr> 319 <td>"{@code none}"</td> 320 <td>The activity does not create a new task for the activity. This is the default value, which 321 creates a new task only when {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} is set. 322 The overview screen treats the activity as it would by default: it displays a single task for 323 the app, which resumes from whatever activity the user last invoked.</td> 324</tr><tr> 325 <td>"{@code never}"</td> 326 <td>This activity is not launched into a new document even if the Intent contains 327 {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT}. Setting this overrides the behavior 328 of the {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and 329 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} flags, if either of these are set in 330 the activity, and the overview screen displays a single task for the app, which resumes from 331 whatever activity the user last invoked.</td> 332</tr> 333</table> 334 335<p class="note"><strong>Note:</strong> For values other than "{@code none}" and "{@code never}" the 336activity must be defined with {@code launchMode="standard"}. If this attribute is not specified, 337{@code documentLaunchMode="none"} is used.</p> 338</dd> 339 340<dt><a name="enabled"></a>{@code android:enabled}</dt> 341<dd>Whether or not the activity can be instantiated by the system — 342{@code "true"} if it can be, and "{@code false}" if not. The default value 343is "{@code true}". 344 345<p> 346The <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a> 347</code> element has its own<code> 348<a href="{@docRoot}guide/topics/manifest/application-element.html#enabled">enabled</a></code> 349attribute that applies to all application components, including activities. The 350<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 351and {@code <activity>} attributes must both be "{@code true}" (as they both 352are by default) for the system to be able to instantiate the activity. If either 353is "{@code false}", it cannot be instantiated. 354</p></dd> 355 356<dt><a name="exclude"></a>{@code android:excludeFromRecents}</dt> 357<dd>Whether or not the task initiated by this activity should be excluded from the list of recently 358used applications, the <a href="{@docRoot}guide/components/recents.html"> 359overview screen</a>. That is, when this activity is the root activity of a new 360task, this attribute determines whether the task should not appear in the list of recent apps. Set 361"{@code true}" if the task should be <em>excluded</em> from the list; set "{@code false}" if it 362should be <em>included</em>. The default value is "{@code false}". 363</p></dd> 364 365<dt><a name="exported"></a>{@code android:exported}</dt> 366<dd>Whether or not the activity can be launched by components of other 367applications — "{@code true}" if it can be, and "{@code false}" if not. 368If "{@code false}", the activity can be launched only by components of the 369same application or applications with the same user ID. 370 371<p> 372The default value depends on whether the activity contains intent filters. The 373absence of any filters means that the activity can be invoked only by specifying 374its exact class name. This implies that the activity is intended only for 375application-internal use (since others would not know the class name). So in 376this case, the default value is "{@code false}". 377On the other hand, the presence of at least one filter implies that the activity 378is intended for external use, so the default value is "{@code true}". 379</p> 380 381<p> 382This attribute is not the only way to limit an activity's exposure to other 383applications. You can also use a permission to limit the external entities that 384can invoke the activity (see the 385<code><a href="{@docRoot}guide/topics/manifest/activity-element.html#prmsn">permission</a></code> 386attribute). 387</p></dd> 388 389<dt><a name="finish"></a>{@code android:finishOnTaskLaunch}</dt> 390<dd>Whether or not an existing instance of the activity should be shut down 391(finished) whenever the user again launches its task (chooses the task on the 392home screen) — "{@code true}" if it should be shut down, and "{@code false}" 393if not. The default value is "{@code false}". 394 395<p> 396If this attribute and 397<code><a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">allowTaskReparenting</a></code> 398are both "{@code true}", this attribute trumps the other. The affinity of the 399activity is ignored. The activity is not re-parented, but destroyed. 400</p> 401 402<dt><a name="hwaccel"></a>{@code android:hardwareAccelerated}</dt> 403<dd>Whether or not hardware-accelerated rendering should be enabled for this 404Activity — "{@code true}" if it should be enabled, and "{@code false}" if 405not. The default value is "{@code false}". 406 407 408<p>Starting from Android 3.0, a hardware-accelerated OpenGL renderer is 409available to applications, to improve performance for many common 2D graphics 410operations. When the hardware-accelerated renderer is enabled, most operations 411in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated. 412This results in smoother animations, smoother scrolling, and improved 413responsiveness overall, even for applications that do not explicitly make use 414the framework's OpenGL libraries. Because of the increased resources required to 415enable hardware acceleration, your app will consume more RAM.</p> 416 417<p>Note that not all of the OpenGL 2D operations are accelerated. If you enable 418the hardware-accelerated renderer, test your application to ensure that it can 419make use of the renderer without errors.</p> 420</dd> 421 422<dt><a name="icon"></a>{@code android:icon}</dt> 423<dd>An icon representing the activity. The icon is displayed to users when 424a representation of the activity is required on-screen. For example, icons 425for activities that initiate tasks are displayed in the launcher window. 426The icon is often accompanied by a label (see the <a href="#label">{@code 427android:label}</a> attribute). 428</p> 429 430<p> 431This attribute must be set as a reference to a drawable resource containing 432the image definition. If it is not set, the icon specified for the application 433as a whole is used instead (see the 434<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 435element's <code><a href="{@docRoot}guide/topics/manifest/application-element.html#icon">icon</a></code> attribute). 436</p> 437 438<p> 439The activity's icon — whether set here or by the 440<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 441element — is also the default icon for all the activity's intent filters (see the 442<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> element's 443<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#icon">icon</a></code> attribute). 444</p></dd> 445 446<dt><a name="label"></a>{@code android:label}</dt> 447<dd>A user-readable label for the activity. The label is displayed on-screen 448when the activity must be represented to the user. It's often displayed along 449with the activity icon. 450 451<p> 452If this attribute is not set, the label set for the application as a whole is 453used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element's 454<code><a href="{@docRoot}guide/topics/manifest/application-element.html#label">label</a></code> attribute). 455</p> 456 457<p> 458The activity's label — whether set here or by the 459<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> element — is also the 460default label for all the activity's intent filters (see the 461<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html"><intent-filter></a></code> element's 462<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#label">label</a></code> attribute). 463</p> 464 465<p> 466The label should be set as a reference to a string resource, so that 467it can be localized like other strings in the user interface. 468However, as a convenience while you're developing the application, 469it can also be set as a raw string. 470</p></dd> 471 472<dt><a name="lmode"></a>{@code android:launchMode}</dt> 473<dd>An instruction on how the activity should be launched. There are four modes 474that work in conjunction with activity flags ({@code FLAG_ACTIVITY_*} constants) 475in {@link android.content.Intent} objects to determine what should happen when 476the activity is called upon to handle an intent. They are:</p> 477 478<p style="margin-left: 2em">"{@code standard}" 479<br>"{@code singleTop}" 480<br>"{@code singleTask}" 481<br>"{@code singleInstance}"</p> 482 483<p> 484The default mode is "{@code standard}". 485</p> 486 487<p> 488As shown in the table below, the modes fall into two main groups, with 489"{@code standard}" and "{@code singleTop}" activities on one side, and 490"{@code singleTask}" and "{@code singleInstance}" activities on the other. 491An activity with the "{@code standard}" or "{@code singleTop}" launch mode 492can be instantiated multiple times. The instances can belong to any task 493and can be located anywhere in the activity stack. Typically, they're 494launched into the task that called 495<code>{@link android.content.Context#startActivity startActivity()}</code> 496(unless the Intent object contains a 497<code>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</code> 498instruction, in which case a different task is chosen — see the 499<a href="#aff">taskAffinity</a> attribute). 500</p> 501 502<p> 503In contrast, "<code>singleTask</code>" and "<code>singleInstance</code>" activities 504can only begin a task. They are always at the root of the activity stack. 505Moreover, the device can hold only one instance of the activity at a time 506— only one such task. 507</p> 508 509<p> 510The "{@code standard}" and "{@code singleTop}" modes differ from each other 511in just one respect: Every time there's a new intent for a "{@code standard}" 512activity, a new instance of the class is created to respond to that intent. 513Each instance handles a single intent. 514Similarly, a new instance of a "{@code singleTop}" activity may also be 515created to handle a new intent. However, if the target task already has an 516existing instance of the activity at the top of its stack, that instance 517will receive the new intent (in an 518{@link android.app.Activity#onNewIntent onNewIntent()} call); 519a new instance is not created. 520In other circumstances — for example, if an existing instance of the 521"{@code singleTop}" activity is in the target task, but not at the top of 522the stack, or if it's at the top of a stack, but not in the target task 523— a new instance would be created and pushed on the stack. 524</p> 525 526<p>Similarly, if you 527<a href="{@docRoot}training/implementing-navigation/ancestral.html">navigate 528up</a> to an activity on the current stack, the behavior is determined by the 529parent activity's launch mode. If the parent activity has launch mode {@code 530singleTop} (or the <code>up</code> intent contains {@link 531android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}), the parent is brought to the 532top of the stack, and its state is preserved. The navigation intent is received 533by the parent activity's {@link android.app.Activity#onNewIntent onNewIntent()} 534method. If the parent activity has launch mode {@code standard} (and the 535<code>up</code> intent does not contain {@link 536android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}), the current activity and its 537parent are both popped off the stack, and a new instance of the parent activity 538is created to receive the navigation intent. 539</p> 540 541 542<p> 543The "{@code singleTask}" and "{@code singleInstance}" modes also differ from 544each other in only one respect: A "{@code singleTask}" activity allows other 545activities to be part of its task. It's always at the root of its task, but 546other activities (necessarily "{@code standard}" and "{@code singleTop}" 547activities) can be launched into that task. A "{@code singleInstance}" 548activity, on the other hand, permits no other activities to be part of its task. 549It's the only activity in the task. If it starts another activity, that 550activity is assigned to a different task — as if {@code 551FLAG_ACTIVITY_NEW_TASK} was in the intent. 552</p> 553 554<table> 555<tr> 556<th>Use Cases</th> 557<th>Launch Mode</th> 558<th>Multiple Instances?</th> 559<th>Comments</th> 560</tr> 561<tr> 562<td rowspan="2" style="width:20%;">Normal launches for most activities</td> 563<td>"<code>standard</code>"</td> 564<td>Yes</td> 565<td>Default. The system always creates a new instance of the activity in the 566target task and routes the intent to it.</td> 567</tr> 568<tr> 569<td>"<code>singleTop</code>"</td> 570<td>Conditionally</td> 571<td>If an instance of the activity already exists at the top of the target task, 572the system routes the intent to that instance through a call to its {@link 573android.app.Activity#onNewIntent onNewIntent()} method, rather than creating a 574new instance of the activity.</td> 575</tr> 576<tr> 577<td rowspan="2">Specialized launches<br> 578<em>(not recommended for general use)</em></td> 579<td>"<code>singleTask</code>"</td> 580<td>No</td> 581<td>The system creates the activity at the root of a new task and routes the 582intent to it. However, if an instance of the activity already exists, the system 583routes the intent to existing instance through a call to its {@link 584android.app.Activity#onNewIntent onNewIntent()} method, rather than creating a 585new one.</td> 586</tr> 587<tr> 588<td>"<code>singleInstance</code>"</td> 589<td>No</td> 590<td>Same as "<code>singleTask"</code>, except that the system doesn't launch any 591other activities into the task holding the instance. The activity is always the 592single and only member of its task.</td> 593</tr> 594</table> 595 596<p>As shown in the table above, <code>standard</code> is the default mode and is 597appropriate for most types of activities. <code>SingleTop</code> is also a 598common and useful launch mode for many types of activities. The other modes 599— <code>singleTask</code> and <code>singleInstance</code> — are 600<span style="color:red">not appropriate for most applications</span>, 601since they result in an interaction model that is likely to be unfamiliar to 602users and is very different from most other applications. 603 604<p>Regardless of the launch mode that you choose, make sure to test the usability 605of the activity during launch and when navigating back to it from 606other activities and tasks using the <em>Back</em> button. </p> 607 608<p>For more information on launch modes and their interaction with Intent 609flags, see the 610<a href="{@docRoot}guide/components/tasks-and-back-stack.html">Tasks and Back Stack</a> 611document. 612</p> 613</dd> 614 615<dt><a name="maxrecents"></a>{@code android:maxRecents}</dt> 616<dd>The maximum number of tasks rooted at this activity in the <a href="{@docRoot}guide/components/recents.html"> 617overview screen</a>. When this number of entries is reached, the system removes the least-recently 618used instance from the overview screen. Valid values are 1 through 50 (25 on low memory devices); 619zero is invalid. This must be an integer value, such as 50. The default value is 16. 620</dd> 621 622<dt><a name="multi"></a>{@code android:multiprocess}</dt> 623<dd>Whether an instance of the activity can be launched into the process of the component 624that started it — "{@code true}" if it can be, and "{@code false}" if not. 625The default value is "{@code false}". 626 627<p> 628Normally, a new instance of an activity is launched into the process of the 629application that defined it, so all instances of the activity run in the same 630process. However, if this flag is set to "{@code true}", instances of the 631activity can run in multiple processes, allowing the system to create instances 632wherever they are used (provided permissions allow it), something that is almost 633never necessary or desirable. 634</p></dd> 635 636<dt><a name="nm"></a>{@code android:name}</dt> 637<dd>The name of the class that implements the activity, a subclass of 638{@link android.app.Activity}. The attribute value should be a fully qualified 639class name (such as, "{@code com.example.project.ExtracurricularActivity}"). 640However, as a shorthand, if the first character of the name is a period 641(for example, "{@code .ExtracurricularActivity}"), it is appended to the 642package name specified in the 643<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 644element. 645<p>Once you publish your application, you <a 646href="http://android-developers.blogspot.com/2011/06/things-that-cannot-change.html">should not 647change this name</a> (unless you've set <code><a 648href="#exported">android:exported</a>="false"</code>).</p> 649 650<p> 651There is no default. The name must be specified. 652</p></dd> 653 654<!-- ##api level 3## --> 655<dt><a name="nohist"></a>{@code android:noHistory}</dt> 656<dd>Whether or not the activity should be removed from the activity stack and 657finished (its <code>{@link android.app.Activity#finish finish()}</code> 658method called) when the user navigates away from it and it's no longer 659visible on screen — "{@code true}" if it should be finished, and 660"{@code false}" if not. The default value is "{@code false}". 661 662<p> 663A value of "{@code true}" means that the activity will not leave a 664historical trace. It will not remain in the activity stack for the task, 665so the user will not be able to return to it. 666</p> 667 668<p> 669This attribute was introduced in API Level 3. 670</p> 671</dd> 672 673<!-- api level 16 --> 674<dt><a name="parent"></a>{@code android:parentActivityName}</dt> 675<dd>The class name of the logical parent of the activity. The name here must match the class 676 name given to the corresponding {@code <activity>} element's 677 <a href="#nm"><code>android:name</code></a> attribute. 678 679<p>The system reads this attribute to determine which activity should be started when 680 the user presses the Up button in the action bar. The system can also use this information to 681 synthesize a back stack of activities with {@link android.app.TaskStackBuilder}.</p> 682 683<p>To support API levels 4 - 16, you can also declare the parent activity with a {@code 684<meta-data>} element that specifies a value for {@code "android.support.PARENT_ACTIVITY"}. 685For example:</p> 686<pre> 687<activity 688 android:name="com.example.app.ChildActivity" 689 android:label="@string/title_child_activity" 690 android:parentActivityName="com.example.myfirstapp.MainActivity" > 691 <!-- Parent activity meta-data to support API level 4+ --> 692 <meta-data 693 android:name="android.support.PARENT_ACTIVITY" 694 android:value="com.example.app.MainActivity" /> 695</activity> 696</pre> 697 698<p>For more information about declaring the parent activity to support Up navigation, 699read <a href="{@docRoot}training/implementing-navigation/ancestral.html">Providing Up 700Navigation</a>.</p> 701 702<p> 703This attribute was introduced in API Level 16. 704</p> 705</dd> 706 707 708 709<dt><a name="prmsn"></a>{@code android:permission}</dt> 710<dd>The name of a permission that clients must have to launch the activity 711or otherwise get it to respond to an intent. If a caller of 712<code>{@link android.content.Context#startActivity startActivity()}</code> or 713<code>{@link android.app.Activity#startActivityForResult startActivityForResult()}</code> 714has not been granted the specified permission, its intent will not be 715delivered to the activity. 716 717<p> 718If this attribute is not set, the permission set by the 719<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 720element's 721<code><a href="{@docRoot}guide/topics/manifest/application-element.html#prmsn">permission</a></code> 722attribute applies to the activity. If neither attribute is set, the activity is 723not protected by a permission. 724</p> 725 726<p> 727For more information on permissions, see the 728<a href="{@docRoot}guide/topics/manifest/manifest-intro.html#sectperm">Permissions</a> 729section in the introduction and another document, 730<a href="{@docRoot}guide/topics/security/security.html">Security and 731Permissions</a>. 732</p></dd> 733 734<dt><a name="proc"></a>{@code android:process}</dt> 735<dd>The name of the process in which the activity should run. Normally, all components of an 736application run in a default process name created for the application and you do 737not need to use this attribute. But if necessary, you can override the default process 738name with this attribute, allowing you to spread your app components across 739multiple processes. 740 741<p> 742If the name assigned to this attribute begins with a colon (':'), a new 743process, private to the application, is created when it's needed and 744the activity runs in that process. 745If the process name begins with a lowercase character, the activity will run 746in a global process of that name, provided that it has permission to do so. 747This allows components in different applications to share a process, reducing 748resource usage. 749</p> 750 751<p>The <code><a href="{@docRoot}guide/topics/manifest/application-element.html" 752><application></a></code> element's 753<code><a href="{@docRoot}guide/topics/manifest/application-element.html#proc">process</a></code> 754attribute can set a different default process name for all components. 755</dd> 756 757<dt><a name="relinquish"></a>{@code android:relinquishTaskIdentity}</dt> 758<dd>Whether or not the activity relinquishes its task identifiers to an activity above it in the 759task stack. A task whose root activity has this attribute set to "{@code true}" replaces the base 760Intent with that of the next activity in the task. If the next activity also has this attribute set 761to "{@code true}" then it will yield the base Intent to any activity that it launches in the same 762task. This continues for each activity until an activity is encountered which has this attribute set 763to "{@code false}". The default value is "{@code false}". 764 765<p>This attribute set to "{@code true}" also permits the activity's use of the 766{@link android.app.ActivityManager.TaskDescription} to change labels, colors 767and icons in the <a href="{@docRoot}guide/components/recents.html">overview screen</a>.</p> 768</dd> 769 770 771<dt><a name="screen"></a>{@code android:screenOrientation}</dt> 772<dd>The orientation of the activity's display on the device. 773 774<p>The value can be any one of the following strings:</p> 775 776<table> 777<tr> 778 <td>"{@code unspecified}"</td> 779 <td>The default value. The system chooses the orientation. The policy it 780 uses, and therefore the choices made in specific contexts, may differ 781 from device to device.</td> 782</tr><tr> 783 <td>"{@code behind}"</td> 784 <td>The same orientation as the activity that's immediately beneath it in 785 the activity stack.</td> 786</tr><tr> 787 <td>"{@code landscape}"</td> 788 <td>Landscape orientation (the display is wider than it is tall).</td> 789</tr><tr> 790 <td>"{@code portrait}"</td> 791 <td>Portrait orientation (the display is taller than it is wide).</td> 792</tr><tr> 793 <td>"{@code reverseLandscape}"</td> 794 <td>Landscape orientation in the opposite direction from normal landscape. 795<em>Added in API level 9.</em></td> 796</tr><tr> 797 <td>"{@code reversePortrait}"</td> 798 <td>Portrait orientation in the opposite direction from normal portrait. 799<em>Added in API level 9.</em></td> 800</tr><tr> 801 <td>"{@code sensorLandscape}"</td> 802 <td>Landscape orientation, but can be either normal or reverse landscape based on the device 803sensor. 804<em>Added in API level 9.</em></td> 805</tr><tr> 806 <td>"{@code sensorPortrait}"</td> 807 <td>Portrait orientation, but can be either normal or reverse portrait based on the device 808sensor. 809<em>Added in API level 9.</em></td> 810</tr><tr> 811 <td>"{@code userLandscape}"</td> 812 <td>Landscape orientation, but can be either normal or reverse landscape based on the device 813sensor and the user's sensor preference. If the user has locked sensor-based rotation, this behaves 814the same as {@code landscape}, otherwise it behaves the same as {@code sensorLandscape}. 815<em>Added in API level 18.</em></td> 816</tr><tr> 817 <td>"{@code userPortrait}"</td> 818 <td>Portrait orientation, but can be either normal or reverse portrait based on the device 819sensor and the user's sensor preference. If the user has locked sensor-based rotation, this behaves 820the same as {@code portrait}, otherwise it behaves the same as {@code sensorPortrait}. 821<em>Added in API level 18.</em></td> 822</tr><tr> 823 <td>"{@code sensor}"</td> 824 <td>The orientation is determined by the device orientation sensor. The orientation of the 825display depends on how the user is holding the device; it changes when the user rotates the 826device. Some devices, though, will not rotate to all four possible orientations, by default. To 827allow all four orientations, use {@code "fullSensor"}.</td> 828</tr><tr> 829 <td>"{@code fullSensor}"</td> 830 <td>The orientation is determined by the device orientation sensor for any of the 4 orientations. 831This is similar to {@code "sensor"} except this allows any of the 4 possible screen orientations, 832regardless of what the device will normally do (for example, some devices won't normally use reverse 833portrait or reverse landscape, but this enables those). <em>Added in API level 9.</em></td> 834</tr><tr> 835 <td>"{@code nosensor}"</td> 836 <td>The orientation is determined without reference to a physical orientation sensor. The sensor 837is ignored, so the display will not rotate based on how the user moves the device. Except for this 838distinction, the system chooses the orientation using the same policy as for the "{@code 839unspecified}" setting.</td> 840</tr><tr> 841 <td>"{@code user}"</td> 842 <td>The user's current preferred orientation.</td> 843</tr><tr> 844 <td>"{@code fullUser}"</td> 845 <td>If the user has locked sensor-based rotation, this behaves the same as {@code user}, 846 otherwise it behaves the same as {@code fullSensor} and allows any of the 4 possible 847 screen orientations. 848 <em>Added in API level 18.</em></td> 849</tr><tr> 850 <td>"{@code locked}"</td> 851 <td>Locks the orientation to its current rotation, whatever that is. 852<em>Added in API level 18.</em></td> 853</tr> 854</table> 855 856<p class="note"><strong>Note:</strong> When you declare one of the landscape or portrait values, 857it is considered a hard requirement for the orientation in which the activity runs. As such, 858the value you declare enables filtering by services such as Google Play so your application is 859available only to devices that support the orientation required by your activities. For 860example, if you declare either {@code "landscape"}, {@code "reverseLandscape"}, or 861{@code "sensorLandscape"}, then your application will be available only to devices that support 862landscape orientation. However, you should also explicitly declare that 863your application requires either portrait or landscape orientation with the <a 864href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a> 865element. For example, <code><uses-feature 866android:name="android.hardware.screen.portrait"/></code>. This is purely a filtering behavior 867provided by Google Play (and other services that support it) and the platform itself does not 868control whether your app can be installed when a device supports only certain orientations.</p> 869 870</dd> 871 872<dt><a name="state"></a>{@code android:stateNotNeeded}</dt> 873<dd>Whether or not the activity can be killed and successfully restarted 874without having saved its state — "{@code true}" if it can be restarted 875without reference to its previous state, and "{@code false}" if its previous 876state is required. The default value is "{@code false}". 877 878<p> 879Normally, before an activity is temporarily shut down to save resources, its 880<code>{@link android.app.Activity#onSaveInstanceState onSaveInstanceState()}</code> 881method is called. This method stores the current state of the activity in a 882{@link android.os.Bundle} object, which is then passed to 883<code>{@link android.app.Activity#onCreate onCreate()}</code> when the activity 884is restarted. If this attribute is set to "{@code true}", 885{@code onSaveInstanceState()} may not be called and {@code onCreate()} will 886be passed {@code null} instead of the Bundle — just as it was when the 887activity started for the first time. 888</p> 889 890<p> 891A "{@code true}" setting ensures that the activity can be restarted in the 892absence of retained state. For example, the activity that displays the 893home screen uses this setting to make sure that it does not get removed if it 894crashes for some reason. 895</p></dd> 896 897<dt><a name="aff"></a>{@code android:taskAffinity}</dt> 898<dd>The task that the activity has an affinity for. Activities with 899the same affinity conceptually belong to the same task (to the same 900"application" from the user's perspective). The affinity of a task 901is determined by the affinity of its root activity. 902 903<p> 904The affinity determines two things — the task that the activity is re-parented 905to (see the <code><a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">allowTaskReparenting</a></code> 906attribute) and the task that will house the activity when it is launched 907with the <code>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</code> 908flag. 909</p> 910 911<p> 912By default, all activities in an application have the same affinity. You 913can set this attribute to group them differently, and even place 914activities defined in different applications within the same task. To 915specify that the activity does not have an affinity for any task, set 916it to an empty string. 917 918<p> 919If this attribute is not set, the activity inherits the affinity set 920for the application (see the 921<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 922element's 923<code><a href="{@docRoot}guide/topics/manifest/application-element.html#aff">taskAffinity</a></code> 924attribute). The name of the default affinity for an application is 925the package name set by the 926<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html"><manifest></a></code> 927element. 928</p> 929 930<dt><a name="theme"></a>{@code android:theme}</dt> 931<dd>A reference to a style resource defining an overall theme for the activity. 932This automatically sets the activity's context to use this theme (see 933<code>{@link android.content.Context#setTheme setTheme()}</code>, and may also 934cause "starting" animations prior to the activity being launched (to better 935match what the activity actually looks like). 936 937<p> 938If this attribute is not set, the activity inherits the theme set for the 939application as a whole — from the 940<code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 941element's 942<code><a href="{@docRoot}guide/topics/manifest/application-element.html#theme">theme</a></code> 943attribute. If that attribute is also not set, the default system theme is used. For more 944information, see the <a 945href="{@docRoot}guide/topics/ui/themes.html">Styles and Themes</a> developer guide. 946</p> 947<dd> 948 949<!-- ##api level 14## --> 950<dt><a name="uioptions"></a>{@code android:uiOptions}</dt> 951<dd>Extra options for an activity's UI. 952 <p>Must be one of the following values.</p> 953 954 <table> 955 <tr><th>Value</th><th>Description</th></tr> 956 <tr><td>{@code "none"}</td><td>No extra UI options. This is the default.</td></tr> 957 <tr><td>{@code "splitActionBarWhenNarrow"}</td><td>Add a bar at 958the bottom of the screen to display action items in the {@link android.app.ActionBar}, when 959constrained for horizontal space (such as when in portrait mode on a handset). Instead of a small 960number of action items appearing in the action bar at the top of the screen, the action bar is 961split into the top navigation section and the bottom bar for action items. This ensures a reasonable 962amount of space is made available not only for the action items, but also for navigation and title 963elements at the top. Menu items are not split across the two bars; they always appear 964together.</td></tr> 965 </table> 966 <p>For more information about the action bar, see the <a 967href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar</a> developer guide.</p> 968 <p>This attribute was added in API level 14.</p> 969</dd> 970 971 972<!-- ##api level 3## --> 973<dt><a name="wsoft"></a>{@code android:windowSoftInputMode}</dt> 974<dd>How the main window of the activity interacts with the window containing 975the on-screen soft keyboard. The setting for this attribute affects two 976things: 977 978<ul> 979<li>The state of the soft keyboard — whether it is hidden or visible 980— when the activity becomes the focus of user attention.</li> 981 982<li>The adjustment made to the activity's main window — whether it is 983resized smaller to make room for the soft keyboard or whether its contents 984pan to make the current focus visible when part of the window is covered by 985the soft keyboard.</li> 986</ul> 987 988<p> 989The setting must be one of the values listed in the following table, or a 990combination of one "{@code state...}" value plus one "{@code adjust...}" 991value. Setting multiple values in either group — multiple 992"{@code state...}" values, for example — has undefined results. 993Individual values are separated by a vertical bar ({@code |}). For example: 994</p> 995 996<pre><activity android:windowSoftInputMode="stateVisible|adjustResize" . . . ></pre> 997 998<p> 999Values set here (other than "{@code stateUnspecified}" and 1000"{@code adjustUnspecified}") override values set in the theme. 1001</p> 1002 1003<table> 1004<tr> 1005 <th>Value</th> 1006 <th>Description</th> 1007</tr><tr> 1008 <td>"{@code stateUnspecified}"</td> 1009 <td>The state of the soft keyboard (whether it is hidden or visible) 1010 is not specified. The system will choose an appropriate state or 1011 rely on the setting in the theme. 1012 1013 <p> 1014 This is the default setting for the behavior of the soft keyboard. 1015 </p></td> 1016</tr></tr> 1017 <td>"{@code stateUnchanged}"</td> 1018 <td>The soft keyboard is kept in whatever state it was last in, 1019 whether visible or hidden, when the activity comes to the fore.</td> 1020</tr></tr> 1021 <td>"{@code stateHidden}"</td> 1022 <td>The soft keyboard is hidden when the user chooses the activity 1023 — that is, when the user affirmatively navigates forward to the 1024 activity, rather than backs into it because of leaving another activity.</td> 1025</tr></tr> 1026 <td>"{@code stateAlwaysHidden}"</td> 1027 <td>The soft keyboard is always hidden when the activity's main window 1028 has input focus.</td> 1029</tr></tr> 1030 <td>"{@code stateVisible}"</td> 1031 <td>The soft keyboard is visible when that's normally appropriate 1032 (when the user is navigating forward to the activity's main window).</td> 1033</tr></tr> 1034 <td>"{@code stateAlwaysVisible}"</td> 1035 <td>The soft keyboard is made visible when the user chooses the 1036 activity — that is, when the user affirmatively navigates forward 1037 to the activity, rather than backs into it because of leaving another 1038 activity.</td> 1039</tr></tr> 1040 <td>"{@code adjustUnspecified}"</td> 1041 <td>It is unspecified whether the activity's main window resizes 1042 to make room for the soft keyboard, or whether the contents 1043 of the window pan to make the current focus visible on-screen. 1044 The system will automatically select one of these modes depending 1045 on whether the content of the window has any layout views that 1046 can scroll their contents. If there is such a view, the window 1047 will be resized, on the assumption that scrolling can make all 1048 of the window's contents visible within a smaller area. 1049 1050 <p> 1051 This is the default setting for the behavior of the main window. 1052 </p></td> 1053</tr></tr> 1054 <td>"{@code adjustResize}"</td> 1055 <td>The activity's main window is always resized to make room for 1056 the soft keyboard on screen.</td> 1057</tr></tr> 1058 <td>"{@code adjustPan}"</td> 1059 <td>The activity's main window is not resized to make room for the soft 1060 keyboard. Rather, the contents of the window are automatically 1061 panned so that the current focus is never obscured by the keyboard 1062 and users can always see what they are typing. This is generally less 1063 desirable than resizing, because the user may need to close the soft 1064 keyboard to get at and interact with obscured parts of the window.</td> 1065</tr> 1066</table> 1067 1068<p> 1069This attribute was introduced in API Level 3. 1070</p></dd> 1071</dl></dd> 1072 1073<!-- ##api level indication## --> 1074<dt>introduced in:</dt> 1075<dd>API Level 1 for all attributes except for 1076<code><a href="#nohist">noHistory</a></code> and 1077<code><a href="#wsoft">windowSoftInputMode</a></code>, which were added in API 1078Level 3.</dd> 1079 1080<dt>see also:</dt> 1081<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code> 1082<br/><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></a></code></dd> 1083</dl> 1084