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