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