activity-element.jd revision cd1b08e1e239269f7d0d48119505313f52d3dd5a
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">&lt;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"] &gt;   <!-- ##api level 3## -->
43    . . .
44&lt;/activity&gt;</pre></dd>
45
46<dt>contained in:</dt>
47<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code></dd>
48
49<dt>can contain:</dt>
50<dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code>
51<br/><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html">&lt;meta-data&gt;</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 &lt;activity&gt;} 
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 &mdash; "{@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">&lt;application&gt;</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 &mdash; "{@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 &mdash; 
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 BACK or HOME to last leave it.  
139When 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 HOME, 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 
150HOME 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 |}' &mdash; 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 &mdash;
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 &mdash;
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 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; 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 &mdash; 
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">&lt;application&gt;</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">&lt;application&gt;</a></code> 
269and {@code &lt;activity&gt;} 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 activity should be excluded from the list of recently 
276launched activities that can be displayed to users &mdash; "{@code true}" if 
277it should be excluded, and "{@code false}" if it should be included.  
278The default value is "{@code false}".
279</p></dd>
280
281<dt><a name="exported"></a>{@code android:exported}</dt>
282<dd>Whether or not the activity can be launched by components of other 
283applications &mdash; "{@code true}" if it can be, and "{@code false}" if not.  
284If "{@code false}", the activity can be launched only by components of the 
285same application or applications with the same user ID.  
286
287<p>
288The default value depends on whether the activity contains intent filters.  The 
289absence of any filters means that the activity can be invoked only by specifying 
290its exact class name.  This implies that the activity is intended only for 
291application-internal use (since others would not know the class name).  So in 
292this case, the default value is "{@code false}".
293On the other hand, the presence of at least one filter implies that the activity 
294is intended for external use, so the default value is "{@code true}".
295</p>
296
297<p>
298This attribute is not the only way to limit an activity's exposure to other
299applications.  You can also use a permission to limit the external entities that 
300can invoke the activity  (see the 
301<code><a href="{@docRoot}guide/topics/manifest/activity-element.html#prmsn">permission</a></code> 
302attribute).
303</p></dd>
304
305<dt><a name="finish"></a>{@code android:finishOnTaskLaunch}</dt>
306<dd>Whether or not an existing instance of the activity should be shut down 
307(finished) whenever the user again launches its task (chooses the task on the 
308home screen) &mdash; "{@code true}" if it should be shut down, and "{@code false}" 
309if not.  The default value is "{@code false}". 
310
311<p>
312If this attribute and 
313<code><a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">allowTaskReparenting</a></code> 
314are both "{@code true}", this attribute trumps the other.  The affinity of the 
315activity is ignored.  The activity is not re-parented, but destroyed.
316</p>
317
318<dt><a name="hwaccel"></a>{@code android:hardwareAccelerated}</dt>
319<dd>Whether or not hardware-accelerated rendering should be enabled for this
320Activity &mdash; "{@code true}" if it should be enabled, and "{@code false}" if
321not. The default value is "{@code false}".
322
323<p>Starting from Android 3.0, a hardware-accelerated OpenGL renderer is
324available to applications, to improve performance for many common 2D graphics
325operations. When the hardware-accelerated renderer is enabled, most operations
326in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated.
327This results in smoother animations, smoother scrolling, and improved
328responsiveness overall, even for applications that do not explicitly make use
329the framework's OpenGL libraries. </p>
330
331<p>Note that not all of the OpenGL 2D operations are accelerated. If you enable
332the hardware-accelerated renderer, test your application to ensure that it can
333make use of the renderer without errors.</p>
334</dd>
335
336<dt><a name="icon"></a>{@code android:icon}</dt>
337<dd>An icon representing the activity. The icon is displayed to users when 
338a representation of the activity is required on-screen.  For example, icons 
339for activities that initiate tasks are displayed in the launcher window.  
340The icon is often accompanied by a label (see the <a href="#label">{@code
341android:label}</a> attribute).
342</p>
343
344<p>
345This attribute must be set as a reference to a drawable resource containing 
346the image definition.  If it is not set, the icon specified for the application 
347as a whole is used instead (see the 
348<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
349element's <code><a href="{@docRoot}guide/topics/manifest/application-element.html#icon">icon</a></code> attribute).
350</p>
351
352<p>
353The activity's icon &mdash; whether set here or by the 
354<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
355element &mdash; is also the default icon for all the activity's intent filters (see the 
356<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's 
357<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#icon">icon</a></code> attribute). 
358</p></dd>
359
360<dt><a name="label"></a>{@code android:label}</dt>
361<dd>A user-readable label for the activity.  The label is displayed on-screen 
362when the activity must be represented to the user. It's often displayed along 
363with the activity icon.
364
365<p>
366If this attribute is not set, the label set for the application as a whole is 
367used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's 
368<code><a href="{@docRoot}guide/topics/manifest/application-element.html#label">label</a></code> attribute).
369</p>
370
371<p>
372The activity's label &mdash; whether set here or by the 
373<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the 
374default label for all the activity's intent filters (see the 
375<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's 
376<code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#label">label</a></code> attribute). 
377</p>
378
379<p>
380The label should be set as a reference to a string resource, so that
381it can be localized like other strings in the user interface.  
382However, as a convenience while you're developing the application, 
383it can also be set as a raw string.
384</p></dd>
385
386<dt><a name="lmode"></a>{@code android:launchMode}</dt>
387<dd>An instruction on how the activity should be launched.  There are four modes
388that work in conjunction with activity flags ({@code FLAG_ACTIVITY_*} constants) 
389in {@link android.content.Intent} objects to determine what should happen when
390the activity is called upon to handle an intent. They are:</p>
391
392<p style="margin-left: 2em">"{@code standard}"
393<br>"{@code singleTop}"
394<br>"{@code singleTask}"
395<br>"{@code singleInstance}"</p>
396
397<p>
398The default mode is "{@code standard}".
399</p>
400
401<p>
402As shown in the table below, the modes fall into two main groups, with
403"{@code standard}" and "{@code singleTop}" activities on one side, and
404"{@code singleTask}" and "{@code singleInstance}" activities on the other.
405An activity with the "{@code standard}" or "{@code singleTop}" launch mode
406can be instantiated multiple times.  The instances can belong to any task
407and can be located anywhere in the activity stack.  Typically, they're
408launched into the task that called 
409<code>{@link android.content.Context#startActivity startActivity()}</code>
410(unless the Intent object contains a
411<code>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</code>
412instruction, in which case a different task is chosen &mdash; see the
413<a href="#aff">taskAffinity</a> attribute).
414</p>
415
416<p>
417In contrast, "<code>singleTask</code>" and "<code>singleInstance</code>" activities
418can only begin a task.  They are always at the root of the activity stack.
419Moreover, the device can hold only one instance of the activity at a time
420&mdash; only one such task.
421</p>
422
423<p>
424The "{@code standard}" and "{@code singleTop}" modes differ from each other 
425in just one respect:  Every time there's a new intent for a "{@code standard}"
426activity, a new instance of the class is created to respond to that intent.
427Each instance handles a single intent.
428Similarly, a new instance of a "{@code singleTop}" activity may also be
429created to handle a new intent.  However, if the target task already has an
430existing instance of the activity at the top of its stack, that instance
431will receive the new intent (in an
432<code>{@link android.app.Activity#onNewIntent onNewIntent()}</code> call);
433a new instance is not created.
434In other circumstances &mdash; for example, if an existing instance of the
435"{@code singleTop}" activity is in the target task, but not at the top of
436the stack, or if it's at the top of a stack, but not in the target task
437&mdash; a new instance would be created and pushed on the stack.
438</p>
439
440<p>
441The "{@code singleTask}" and "{@code singleInstance}" modes also differ from
442each other in only one respect:  A "{@code singleTask}" activity allows other
443activities to be part of its task. It's always at the root of its task, but
444other activities (necessarily "{@code standard}" and "{@code singleTop}"
445activities) can be launched into that task.  A "{@code singleInstance}"
446activity, on the other hand, permits no other activities to be part of its task.
447It's the only activity in the task.  If it starts another activity, that
448activity is assigned to a different task &mdash; as if {@code
449FLAG_ACTIVITY_NEW_TASK} was in the intent.
450</p>
451
452<table>
453<tr>
454<th>Use Cases</th>
455<th>Launch Mode</th>
456<th>Multiple Instances?</th>
457<th>Comments</th>
458</tr>
459<tr>
460<td rowspan="2" style="width:20%;">Normal launches for most activities</td>
461<td>"<code>standard</code>"</td>
462<td>Yes</td>
463<td>Default. The system always creates a new instance of the activity in the
464target task and routes the intent to it.</td>
465</tr>
466<tr>
467<td>"<code>singleTop</code>"</td>
468<td>Conditionally</td>
469<td>If an instance of the activity already exists at the top of the target task,
470the system routes the intent to that instance through a call to its {@link
471android.app.Activity#onNewIntent onNewIntent()} method, rather than creating a
472new instance of the activity.</td>
473</tr>
474<tr>
475<td rowspan="2">Specialized launches<br>
476<em>(not recommended for general use)</em></td>
477<td>"<code>singleTask</code>"</td>
478<td>No</td>
479<td>The system creates the activity at the root of a new task and routes the
480intent to it. However, if an instance of the activity already exists, the system
481routes the intent to existing instance through a call to its {@link
482android.app.Activity#onNewIntent onNewIntent()} method, rather than creating a
483new one.</td>
484</tr>
485<tr>
486<td>"<code>singleInstance</code>"</td>
487<td>No</td>
488<td>Same as "<code>singleTask"</code>, except that the system doesn't launch any
489other activities into the task holding the instance. The activity is always the
490single and only member of its task.</td>
491</tr>
492</table>
493
494<p>As shown in the table above, <code>standard</code> is the default mode and is
495appropriate for most types of activities. <code>SingleTop</code> is also a
496common and useful launch mode for many types of activities. The other modes
497&mdash; <code>singleTask</code> and <code>singleInstance</code> &mdash; are
498<span style="color:red">not appropriate for most applications</span>,
499since they result in an interaction model that is likely to be unfamiliar to
500users and is very different from most other applications. 
501
502<p>Regardless of the launch mode that you choose, make sure to test the usability
503of the activity during launch and when navigating back to it from
504other activities and tasks using the BACK key. </p>
505
506<p>For more information on launch modes and their interaction with Intent
507flags, see the 
508<a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back Stack</a>
509document.
510</p>
511</dd>
512
513<dt><a name="multi"></a>{@code android:multiprocess}</dt>
514<dd>Whether an instance of the activity can be launched into the process of the component 
515that started it &mdash; "{@code true}" if it can be, and "{@code false}" if not.  
516The default value is "{@code false}".
517
518<p>
519Normally, a new instance of an activity is launched into the process of the 
520application that defined it, so all instances of the activity run in the same 
521process.  However, if this flag is set to "{@code true}", instances of the 
522activity can run in multiple processes, allowing the system to create instances 
523wherever they are used (provided permissions allow it), something that is almost 
524never necessary or desirable.
525</p></dd>
526
527<dt><a name="nm"></a>{@code android:name}</dt>
528<dd>The name of the class that implements the activity, a subclass of 
529{@link android.app.Activity}.  The attribute value should be a fully qualified 
530class name (such as, "{@code com.example.project.ExtracurricularActivity}").  
531However, as a shorthand, if the first character of the name is a period 
532(for example, "{@code .ExtracurricularActivity}"), it is appended to the 
533package name specified in the 
534<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></code> 
535element.
536<p>Once you publish your application, you <a
537href="http://android-developers.blogspot.com/2011/06/things-that-cannot-change.html">should not
538change this name</a> (unless you've set <code><a
539href="#exported">android:exported</a>="false"</code>).</p>
540
541<p>
542There is no default.  The name must be specified.
543</p></dd>
544
545<!-- ##api level 3## -->
546<dt><a name="nohist"></a>{@code android:noHistory}</dt>
547<dd>Whether or not the activity should be removed from the activity stack and
548finished (its <code>{@link android.app.Activity#finish finish()}</code> 
549method called) when the user navigates away from it and it's no longer 
550visible on screen &mdash; "{@code true}" if it should be finished, and 
551"{@code false}" if not.  The default value is "{@code false}".
552
553<p>
554A value of "{@code true}" means that the activity will not leave a
555historical trace.  It will not remain in the activity stack for the task,
556so the user will not be able to return to it.
557</p>
558
559<p>
560This attribute was introduced in API Level 3.
561</p>
562
563<dt><a name="prmsn"></a>{@code android:permission}</dt>
564<dd>The name of a permission that clients must have to launch the activity 
565or otherwise get it to respond to an intent.  If a caller of 
566<code>{@link android.content.Context#startActivity startActivity()}</code> or
567<code>{@link android.app.Activity#startActivityForResult startActivityForResult()}</code>
568has not been granted the specified permission, its intent will not be 
569delivered to the activity.
570
571<p>
572If this attribute is not set, the permission set by the 
573<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
574element's
575<code><a href="{@docRoot}guide/topics/manifest/application-element.html#prmsn">permission</a></code> 
576attribute applies to the activity.  If neither attribute is set, the activity is
577not protected by a permission.
578</p>
579
580<p>
581For more information on permissions, see the 
582<a href="{@docRoot}guide/topics/manifest/manifest-intro.html#sectperm">Permissions</a> 
583section in the introduction and another document, 
584<a href="{@docRoot}guide/topics/security/security.html">Security and
585Permissions</a>.
586</p></dd>
587
588<dt><a name="proc"></a>{@code android:process}</dt>
589<dd>The name of the process in which the activity should run.  Normally, 
590all components of an application run in the default process created for the 
591application.  It has the same name as the application package.  The <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's 
592<code><a href="{@docRoot}guide/topics/manifest/application-element.html#proc">process</a></code> 
593attribute can set a different default for all components.  But each component 
594can override the default, allowing you to spread your application across 
595multiple processes.
596
597<p>
598If the name assigned to this attribute begins with a colon (':'), a new 
599process, private to the application, is created when it's needed and 
600the activity runs in that process.
601If the process name begins with a lowercase character, the activity will run 
602in a global process of that name, provided that it has permission to do so.
603This allows components in different applications to share a process, reducing 
604resource usage.
605</p></dd>
606
607<dt><a name="screen"></a>{@code android:screenOrientation}</dt>
608<dd>The orientation of the activity's display on the device. 
609  
610<p>The value can be any one of the following strings:</p>
611
612<table>
613<tr>
614   <td>"{@code unspecified}"</td>
615   <td>The default value.  The system chooses the orientation.  The policy it
616       uses, and therefore the choices made in specific contexts, may differ 
617       from device to device.</td>
618</tr><tr>
619   <td>"{@code user}"</td>
620   <td>The user's current preferred orientation.</td>
621</tr><tr>
622   <td>"{@code behind}"</td>
623   <td>The same orientation as the activity that's immediately beneath it in 
624       the activity stack.</td>
625</tr><tr>
626   <td>"{@code landscape}"</td>
627   <td>Landscape orientation (the display is wider than it is tall).</td>
628</tr><tr>
629   <td>"{@code portrait}"</td>
630   <td>Portrait orientation (the display is taller than it is wide).</td>
631</tr><tr>
632   <td>"{@code reverseLandscape}"</td>
633   <td>Landscape orientation in the opposite direction from normal landscape.
634<em>Added in API level 9.</em></td>
635</tr><tr>
636   <td>"{@code reversePortrait}"</td>
637   <td>Portrait orientation in the opposite direction from normal portrait.
638<em>Added in API level 9.</em></td>
639</tr><tr>
640   <td>"{@code sensorLandscape}"</td>
641   <td>Landscape orientation, but can be either normal or reverse landscape based on the device
642sensor.
643<em>Added in API level 9.</em></td>
644</tr><tr>
645   <td>"{@code sensorPortrait}"</td>
646   <td>Portrait orientation, but can be either normal or reverse portrait based on the device
647sensor.
648<em>Added in API level 9.</em></td>
649</tr><tr>
650   <td>"{@code sensor}"</td>
651   <td>The orientation is determined by the device orientation sensor.  The orientation of the
652display depends on how the user is holding the device; it changes when the user rotates the
653device. Some devices, though, will not rotate to all four possible orientations, by default. To
654allow all four orientations, use {@code "fullSensor"}.</td>
655</tr><tr>
656   <td>"{@code fullSensor}"</td>
657   <td>The orientation is determined by the device orientation sensor for any of the 4 orientations.
658This is similar to {@code "sensor"} except this allows any of the 4 possible screen orientations,
659regardless of what the device will normally do (for example, some devices won't normally use reverse
660portrait or reverse landscape, but this enables those). <em>Added in API level 9.</em></td>
661</tr><tr>
662   <td>"{@code nosensor}"</td>
663   <td>The orientation is determined without reference to a physical orientation sensor.  The sensor
664is ignored, so the display will not rotate based on how the user moves the device.  Except for this
665distinction, the system chooses the orientation using the same policy as for the "{@code
666unspecified}" setting.</td>
667</tr>
668</table>
669
670<p class="note"><strong>Note:</strong> When you declare one of the landscape or portrait values,
671it is considered a hard requirement for the orientation in which the activity runs. As such,
672the value you declare enables filtering by services such as Android Market so your application is
673available only to devices that support the orientation required by your activities. For
674example, if you declare either {@code "landscape"}, {@code "reverseLandscape"}, or
675{@code "sensorLandscape"}, then your application will be available only to devices that support
676landscape orientation. However, you should also explicitly declare that
677your application requires either portrait or landscape orientation with the <a
678href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code &lt;uses-feature&gt;}</a>
679element. For example, <code>&lt;uses-feature
680android:name="android.hardware.screen.portrait"/></code>. This is purely a filtering behavior
681provided by Android Market (and other services that support it) and the platform itself does not
682control whether your app can be installed when a device supports only certain orientations.</p>
683
684</dd>
685
686<dt><a name="state"></a>{@code android:stateNotNeeded}</dt>
687<dd>Whether or not the activity can be killed and successfully restarted 
688without having saved its state &mdash; "{@code true}" if it can be restarted 
689without reference to its previous state, and "{@code false}" if its previous 
690state is required.  The default value is "{@code false}".
691
692<p>
693Normally, before an activity is temporarily shut down to save resources, its 
694<code>{@link android.app.Activity#onSaveInstanceState onSaveInstanceState()}</code> 
695method is called.  This method stores the current state of the activity in a 
696{@link android.os.Bundle} object, which is then passed to 
697<code>{@link android.app.Activity#onCreate onCreate()}</code> when the activity 
698is restarted.  If this attribute is set to "{@code true}", 
699{@code onSaveInstanceState()} may not be called and {@code onCreate()} will 
700be passed {@code null} instead of the Bundle &mdash; just as it was when the 
701activity started for the first time.
702</p>
703
704<p>
705A "{@code true}" setting ensures that the activity can be restarted in the 
706absence of retained state.  For example, the activity that displays the 
707home screen uses this setting to make sure that it does not get removed if it 
708crashes for some reason. 
709</p></dd>
710
711<dt><a name="aff"></a>{@code android:taskAffinity}</dt>
712<dd>The task that the activity has an affinity for.  Activities with 
713the same affinity conceptually belong to the same task (to the same
714"application" from the user's perspective).  The affinity of a task 
715is determined by the affinity of its root activity. 
716
717<p>
718The affinity determines two things &mdash; the task that the activity is re-parented 
719to (see the <code><a href="{@docRoot}guide/topics/manifest/activity-element.html#reparent">allowTaskReparenting</a></code> 
720attribute) and the task that will house the activity when it is launched 
721with the <code>{@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK}</code> 
722flag.
723</p>
724
725<p>
726By default, all activities in an application have the same affinity.  You
727can set this attribute to group them differently, and even place
728activities defined in different applications within the same task.  To 
729specify that the activity does not have an affinity for any task, set
730it to an empty string.
731
732<p>
733If this attribute is not set, the activity inherits the affinity set 
734for the application (see the 
735<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
736element's 
737<code><a href="{@docRoot}guide/topics/manifest/application-element.html#aff">taskAffinity</a></code>
738attribute).  The name of the default affinity for an application is 
739the package name set by the 
740<code><a href="{@docRoot}guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></code> 
741element.
742</p>
743
744<dt><a name="theme"></a>{@code android:theme}</dt>
745<dd>A reference to a style resource defining an overall theme for the activity.  
746This automatically sets the activity's context to use this theme (see
747<code>{@link android.content.Context#setTheme setTheme()}</code>, and may also 
748cause "starting" animations prior to the activity being launched (to better 
749match what the activity actually looks like).
750
751<p>
752If this attribute is not set, the activity inherits the theme set for the 
753application as a whole &mdash; from the 
754<code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
755element's 
756<code><a href="{@docRoot}guide/topics/manifest/application-element.html#theme">theme</a></code> 
757attribute.  If that attribute is also not set, the default system theme is used. For more
758information, see the <a
759href="{@docRoot}guide/topics/ui/themes.html">Styles and Themes</a> developer guide.
760</p>
761<dd>
762
763<!-- ##api level 14## -->
764<dt><a name="uioptions"></a>{@code android:uiOptions}</dt>
765<dd>Extra options for an activity's UI.
766  <p>Must be one of the following values.</p>
767
768  <table>
769    <tr><th>Value</th><th>Description</th></tr>
770    <tr><td>{@code "none"}</td><td>No extra UI options. This is the default.</td></tr>
771    <tr><td>{@code "splitActionBarWhenNarrow"}</td><td>Add a bar at
772the bottom of the screen to display action items in the {@link android.app.ActionBar}, when
773constrained for horizontal space (such as when in portrait mode on a handset). Instead of a small
774number of action items appearing in the action bar at the top of the screen, the action bar is
775split into the top navigation section and the bottom bar for action items. This ensures a reasonable
776amount of space is made available not only for the action items, but also for navigation and title
777elements at the top. Menu items are not split across the two bars; they always appear
778together.</td></tr>
779  </table>
780  <p>For more information about the action bar, see the <a
781href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar</a> developer guide.</p>
782  <p>This attribute was added in API level 14.</p>
783</dd>
784
785
786<!-- ##api level 3## -->
787<dt><a name="wsoft"></a>{@code android:windowSoftInputMode}</dt>
788<dd>How the main window of the activity interacts with the window containing 
789the on-screen soft keyboard.  The setting for this attribute affects two 
790things: 
791
792<ul> 
793<li>The state of the soft keyboard &mdash; whether it is hidden or visible 
794&mdash; when the activity becomes the focus of user attention.</li>
795
796<li>The adjustment made to the activity's main window &mdash; whether it is 
797resized smaller to make room for the soft keyboard or whether its contents 
798pan to make the current focus visible when part of the window is covered by 
799the soft keyboard.</li>
800</ul>
801
802<p>
803The setting must be one of the values listed in the following table, or a 
804combination of one "{@code state...}" value plus one "{@code adjust...}" 
805value.  Setting multiple values in either group &mdash; multiple 
806"{@code state...}" values, for example &mdash; has undefined results.  
807Individual values are separated by a vertical bar ({@code |}).  For example:
808</p>
809
810<pre>&lt;activity android:windowSoftInputMode="stateVisible|adjustResize" . . . &gt;</pre>
811
812<p>
813Values set here (other than "{@code stateUnspecified}" and 
814"{@code adjustUnspecified}") override values set in the theme.
815</p>
816
817<table>
818<tr>
819   <th>Value</th>
820   <th>Description</th>
821</tr><tr>
822   <td>"{@code stateUnspecified}"</td>
823   <td>The state of the soft keyboard (whether it is hidden or visible) 
824       is not specified.  The system will choose an appropriate state or
825       rely on the setting in the theme.  
826
827       <p>
828       This is the default setting for the behavior of the soft keyboard.
829       </p></td>
830</tr></tr>
831   <td>"{@code stateUnchanged}"</td>
832   <td>The soft keyboard is kept in whatever state it was last in,
833       whether visible or hidden, when the activity comes to the fore.</td>
834</tr></tr>
835   <td>"{@code stateHidden}"</td>
836   <td>The soft keyboard is hidden when the user chooses the activity 
837       &mdash; that is, when the user affirmatively navigates forward to the 
838       activity, rather than backs into it because of leaving another activity.</td>
839</tr></tr>
840   <td>"{@code stateAlwaysHidden}"</td>
841   <td>The soft keyboard is always hidden when the activity's main window 
842       has input focus.</td>
843</tr></tr>
844   <td>"{@code stateVisible}"</td>
845   <td>The soft keyboard is visible when that's normally appropriate 
846       (when the user is navigating forward to the activity's main window).</td>
847</tr></tr>
848   <td>"{@code stateAlwaysVisible}"</td>
849   <td>The soft keyboard is made visible when the user chooses the 
850       activity &mdash; that is, when the user affirmatively navigates forward 
851       to the activity, rather than backs into it because of leaving another 
852       activity.</td>
853</tr></tr>
854   <td>"{@code adjustUnspecified}"</td>
855   <td>It is unspecified whether the activity's main window resizes 
856       to make room for the soft keyboard, or whether the contents 
857       of the window pan to make the currentfocus visible on-screen. 
858       The system will automatically select one of these modes depending
859       on whether the content of the window has any layout views that 
860       can scroll their contents.  If there is such a view, the window 
861       will be resized, on the assumption that scrolling can make all 
862       of the window's contents visible within a smaller area.
863
864       <p>
865       This is the default setting for the behavior of the main window.
866       </p></td>
867</tr></tr>
868   <td>"{@code adjustResize}"</td>
869   <td>The activity's main window is always resized to make room for 
870       the soft keyboard on screen.</td>
871</tr></tr>
872   <td>"{@code adjustPan}"</td>
873   <td>The activity's main window is not resized to make room for the soft
874       keyboard.  Rather, the contents of the window are automatically 
875       panned so that the current focus is never obscured by the keyboard
876       and users can always see what they are typing.  This is generally less 
877       desirable than resizing, because the user may need to close the soft
878       keyboard to get at and interact with obscured parts of the window.</td>
879</tr>
880</table>
881
882<p>
883This attribute was introduced in API Level 3.
884</p></dd>
885</dl></dd>
886
887<!-- ##api level indication## -->
888<dt>introduced in:</dt>
889<dd>API Level 1 for all attributes except for 
890<code><a href="#nohist">noHistory</a></code> and
891<code><a href="#wsoft">windowSoftInputMode</a></code>, which were added in API 
892Level 3.</dd>
893
894<dt>see also:</dt>
895<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
896<br/><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html">&lt;activity-alias&gt;</a></code></dd>
897</dl>
898