It is anything used to contain protect manage, distribute, or introduce raw materials

  • Platform
  • Android Studio
  • Google Play
  • Jetpack
  • Kotlin
  • Docs
    • Overview
    • Guides
    • UI Guide
    • Reference
    • Samples
    • Design & Quality
  • Games

Stay organized with collections Save and categorize content based on your preferences.

syntax:

<activity android:allowEmbedded=["true" | "false"]
          android:allowTaskReparenting=["true" | "false"]
          android:alwaysRetainTaskState=["true" | "false"]
          android:autoRemoveFromRecents=["true" | "false"]
          android:banner="drawable resource"
          android:clearTaskOnLaunch=["true" | "false"]
          android:colorMode=[ "hdr" | "wideColorGamut"]
          android:configChanges=["mcc", "mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "screenLayout", "fontScale",
                                 "uiMode", "orientation", "density",
                                 "screenSize", "smallestScreenSize"]
          android:directBootAware=["true" | "false"]
          android:documentLaunchMode=["intoExisting" | "always" |
                                  "none" | "never"]
          android:enabled=["true" | "false"]
          android:excludeFromRecents=["true" | "false"]
          android:exported=["true" | "false"]
          android:finishOnTaskLaunch=["true" | "false"]
          android:hardwareAccelerated=["true" | "false"]
          android:icon="drawable resource"
          android:immersive=["true" | "false"]
          android:label="string resource"
          android:launchMode=["standard" | "singleTop" |
                              "singleTask" | "singleInstance" | "singleInstancePerTask"]
          android:lockTaskMode=["normal" | "never" |
                              "if_whitelisted" | "always"]
          android:maxRecents="integer"
          android:maxAspectRatio="float"
          android:multiprocess=["true" | "false"]
          android:name="string"
          android:noHistory=["true" | "false"]  
          android:parentActivityName="string" 
          android:persistableMode=["persistRootOnly" | 
                                   "persistAcrossReboots" | "persistNever"]
          android:permission="string"
          android:process="string"
          android:relinquishTaskIdentity=["true" | "false"]
          android:resizeableActivity=["true" | "false"]
          android:screenOrientation=["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]
          android:showForAllUsers=["true" | "false"]
          android:stateNotNeeded=["true" | "false"]
          android:supportsPictureInPicture=["true" | "false"]
          android:taskAffinity="string"
          android:theme="resource or theme"
          android:uiOptions=["none" | "splitActionBarWhenNarrow"]
          android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"] >   
    . . .
</activity>
contained in:<application>can contain:<intent-filter>
<meta-data>
<layout>description:Declares an activity (an Activity subclass) that implements part of the application's visual user interface. All activities must be represented by <activity> elements in the manifest file. Any that are not declared there will not be seen by the system and will never be run. attributes:android:allowEmbedded Indicate that the activity can be launched as the embedded child of another activity. Particularly in the case where the child lives in a container such as a Display owned by another activity. For example, activities that are used for Wear custom notifications must declare this so Wear can display the activity in it's context stream, which resides in another process.

The default value of this attribute is false.

android:allowTaskReparentingWhether or not the activity can move from the task that started it to the task it has an affinity for when that task is next brought to the front — "true" if it can move, and "false" if it must remain with the task where it started.

If this attribute is not set, the value set by the corresponding allowTaskReparenting attribute of the <application> element applies to the activity. The default value is "false".

Normally when an activity is started, it's associated with the task of the activity that started it and it stays there for its entire lifetime. You can use this attribute to force it to be re-parented to the task it has an affinity for when its current task is no longer displayed. Typically, it's used to cause the activities of an application to move to the main task associated with that application.

For example, if an e-mail message contains a link to a web page, clicking the link brings up an activity that can display the page. That activity is defined by the browser application, but is launched as part of the e-mail task. If it's reparented to the browser task, it will be shown when the browser next comes to the front, and will be absent when the e-mail task again comes forward.

The affinity of an activity is defined by the taskAffinity attribute. The affinity of a task is determined by reading the affinity of its root activity. Therefore, by definition, a root activity is always in a task with the same affinity. Since activities with "singleTask" or "singleInstance" launch modes can only be at the root of a task, re-parenting is limited to the "standard" and "singleTop" modes. (See also the launchMode attribute.)

android:alwaysRetainTaskStateWhether or not the state of the task that the activity is in will always be maintained by the system — "true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain situations. The default value is "false". This attribute is meaningful only for the root activity of a task; it's ignored for all other activities.

Normally, the system clears a task (removes all activities from the stack above the root activity) in certain situations when the user re-selects that task from the home screen. Typically, this is done if the user hasn't visited the task for a certain amount of time, such as 30 minutes.

However, when this attribute is "true", users will always return to the task in its last state, regardless of how they get there. This is useful, for example, in an application like the web browser where there is a lot of state (such as multiple open tabs) that users would not like to lose.

android:autoRemoveFromRecentsWhether or not tasks launched by activities with this attribute remains in the overview screen until the last activity in the task is completed. If true, the task is automatically removed from the overview screen. This overrides the caller's use of FLAG_ACTIVITY_RETAIN_IN_RECENTS. It must be a boolean value, either "true" or "false".android:bannerA drawable resource providing an extended graphical banner for its associated item. Use with the <activity> tag to supply a default banner for a specific activity, or with the <application> tag to supply a banner for all application activities.

The system uses the banner to represent an app in the Android TV home screen. Since the banner is displayed only in the home screen, it should only be specified by applications with an activity that handles the CATEGORY_LEANBACK_LAUNCHER intent.

This attribute must be set as a reference to a drawable resource containing the image (for example "@drawable/banner"). There is no default banner.

See Provide a home screen banner in Get Started with TV Apps for more information.

android:clearTaskOnLaunchWhether or not all activities will be removed from the task, except for the root activity, whenever it is re-launched from the home screen — "true" if the task is always stripped down to its root activity, and "false" if not. The default value is "false". This attribute is meaningful only for activities that start a new task (the root activity); it's ignored for all other activities in the task.

When the value is "true", every time users start the task again, they are brought to its root activity regardless of what they were last doing in the task and regardless of whether they used the Back or Home button to leave it. When the value is "false", the task may be cleared of activities in some situations (see the alwaysRetainTaskState attribute), but not always.

Suppose, for example, that someone launches activity P from the home screen, and from there goes to activity Q. The user next presses Home, and then returns to activity P. Normally, the user would see activity Q, since that is what they were last doing in P's task. However, if P set this flag to "true", all of the activities on top of it (Q in this case) would be removed when the user launched activity P from the home screen. So the user would see only P when returning to the task.

If this attribute and allowTaskReparenting are both "true", any activities that can be re-parented are moved to the task they share an affinity with; the remaining activities are then dropped, as described above.

This attribute is ignored if FLAG_ACTIVITY_RESET_TASK_IF_NEEDED is not set.

android:colorMode

Requests the activity to be displayed in wide color gamut mode on compatible devices. In wide color gamut mode, a window can render outside of the SRGB gamut to display more vibrant colors. If the device doesn't support wide color gamut rendering, this attribute has no effect. For more information about rendering in wide color mode, see Enhancing Graphics with Wide Color Content.

android:configChangesLists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.

Note: Use this attribute only in special cases to improve application performance and responsiveness. For more information, see Handle configuration changes.

Any or all of the following strings are valid values for this attribute. Multiple values are separated by '|' — for example, "locale|navigation|orientation".

ValueDescription
"density" The display density has changed — the user might have specified a different display scale, or a different display might now be active.

Added in API level 24.

"fontScale" The font scaling factor has changed — the user has selected a new global font size.
"keyboard" The keyboard type has changed — for example, the user has plugged in an external keyboard.
"keyboardHidden" The keyboard accessibility has changed — for example, the user has revealed the hardware keyboard.
"layoutDirection" The layout direction has changed — for example, changing from left-to-right (LTR) to right-to-left (RTL).

Added in API level 17.

"locale" The locale has changed — the user has selected a new language that text should be displayed in.
"mcc" The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC.
"mnc" The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC.
"navigation" The navigation type (trackball/dpad) has changed. (This should never normally happen.)
"orientation"

The screen orientation has changed — the user has rotated the device.

Note: If your application targets Android 3.2 (API level 13) or higher, also declare the "screenLayout" and "screenSize" configurations because screen layout and screen size can change when a device switches between portrait and landscape orientations.

"screenLayout" The screen layout has changed — a different display might now be active.
"screenSize" The current available screen size has changed.

This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait.

Added in API level 13.

"smallestScreenSize" The physical screen size has changed.

This represents a change in size regardless of orientation, so will only change when the actual physical screen size has changed such as switching to an external display. A change to this configuration corresponds to a change in the smallestWidth configuration.

Added in API level 13.

"touchscreen" The touchscreen has changed. (This should never normally happen.)
"uiMode" The user interface mode has changed — the user has placed the device into a desk or car dock, or the night mode has changed. For more information about the different UI modes, see UiModeManager.

Added in API level 8.

All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.

Note: To handle all Multi-Window related configuration changes use both "screenLayout" and "smallestScreenSize". Multi-Window is supported in Android 7.0 (API level 24) or higher.

android:directBootAware

Whether or not the activity is direct-boot aware; that is, whether or not it can run before the user unlocks the device.

Note: During Direct Boot, an activity in your application can only access the data that is stored in device protected storage.

The default value is "false".

android:documentLaunchModeSpecifies how a new instance of an activity should be added to a task each time it is launched. This attribute permits the user to have multiple documents from the same application appear in the overview screen.

This attribute has four values which produce the following effects when the user opens a document with the application:

ValueDescription
"intoExisting" The system searches for a task whose base intent's ComponentName and data URI match those of the launching intent. If the system finds such a task, the system clears the task, and restarts with the root activity receiving a call to onNewIntent(android.content.Intent). If the system does not find such a task, the system creates a new task.
"always" The activity creates a new task for the document, even if the document is already opened. This is the same as setting both the FLAG_ACTIVITY_NEW_DOCUMENT and FLAG_ACTIVITY_MULTIPLE_TASK flags.
"none" The activity does not create a new task for the activity. This is the default value, which creates a new task only when FLAG_ACTIVITY_NEW_TASK is set. The overview screen treats the activity as it would by default: it displays a single task for the app, which resumes from whatever activity the user last invoked.
"never" This activity is not launched into a new document even if the Intent contains FLAG_ACTIVITY_NEW_DOCUMENT. Setting this overrides the behavior of the FLAG_ACTIVITY_NEW_DOCUMENT and FLAG_ACTIVITY_MULTIPLE_TASK flags, if either of these are set in the activity, and the overview screen displays a single task for the app, which resumes from whatever activity the user last invoked.

Note: For values other than "none" and "never" the activity must be defined with launchMode="standard". If this attribute is not specified, documentLaunchMode="none" is used.

android:enabledWhether or not the activity can be instantiated by the system — "true" if it can be, and "false" if not. The default value is "true".

The <application> element has its own enabled attribute that applies to all application components, including activities. The <application> and <activity> attributes must both be "true" (as they both are by default) for the system to be able to instantiate the activity. If either is "false", it cannot be instantiated.

android:excludeFromRecentsWhether or not the task initiated by this activity should be excluded from the list of recently used applications, the overview screen. That is, when this activity is the root activity of a new task, this attribute determines whether the task should not appear in the list of recent apps. Set "true" if the task should be excluded from the list; set "false" if it should be included. The default value is "false". android:exportedThis element sets whether the activity can be launched by components of other applications:
  • If "true", the activity is accessible to any app, and is launchable by its exact class name.
  • If "false", the activity can be launched only by components of the same application, applications with the same user ID, or privileged system components. This is the default value when there are no intent filters.

If an activity in your app includes intent filters, set this element to "true" to allow other apps to start it. For example, if the activity is the main activity of the app and includes the category "android.intent.category.LAUNCHER".

If this element is set to "false" and an app tries to start the activity, the system throws an ActivityNotFoundException.

This attribute is not the only way to limit an activity's exposure to other applications. Permissions can also be used to limit the external entities that can invoke the activity (see the permission attribute).

android:finishOnTaskLaunchWhether or not an existing instance of the activity should be shut down (finished), except for the root activity, whenever the user again launches its task (chooses the task on the home screen) — "true" if it should be shut down, and "false" if not. The default value is "false".

If this attribute and allowTaskReparenting are both "true", this attribute trumps the other. The affinity of the activity is ignored. The activity is not re-parented, but destroyed.

This attribute is ignored if FLAG_ACTIVITY_RESET_TASK_IF_NEEDED isn't set.

android:hardwareAcceleratedWhether or not hardware-accelerated rendering should be enabled for this Activity — "true" if it should be enabled, and "false" if not. The default value is "false".

Starting from Android 3.0, a hardware-accelerated OpenGL renderer is available to applications, to improve performance for many common 2D graphics operations. When the hardware-accelerated renderer is enabled, most operations in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated. This results in smoother animations, smoother scrolling, and improved responsiveness overall, even for applications that do not explicitly make use the framework's OpenGL libraries. Because of the increased resources required to enable hardware acceleration, your app will consume more RAM.

Note that not all of the OpenGL 2D operations are accelerated. If you enable the hardware-accelerated renderer, test your application to ensure that it can make use of the renderer without errors.

android:iconAn icon representing the activity. The icon is displayed to users when a representation of the activity is required on-screen. For example, icons for activities that initiate tasks are displayed in the launcher window. The icon is often accompanied by a label (see the android:label attribute).

This attribute must be set as a reference to a drawable resource containing the image definition. If it is not set, the icon specified for the application as a whole is used instead (see the <application> element's icon attribute).

The activity's icon — whether set here or by the <application> element — is also the default icon for all the activity's intent filters (see the <intent-filter> element's icon attribute).

android:immersiveSets the immersive mode setting for the current activity. If the android:immersive attribute is set to true in the app's manifest entry for this activity, the ActivityInfo.flags member always has its FLAG_IMMERSIVE bit set, even if the immersive mode is changed at runtime using the setImmersive() method.android:labelA user-readable label for the activity. The label is displayed on-screen when the activity must be represented to the user. It's often displayed along with the activity icon.

If this attribute is not set, the label set for the application as a whole is used instead (see the <application> element's label attribute).

The activity's label — whether set here or by the <application> element — is also the default label for all the activity's intent filters (see the <intent-filter> element's label attribute).

The label should be set as a reference to a string resource, so that it can be localized like other strings in the user interface. However, as a convenience while you're developing the application, it can also be set as a raw string.

android:launchModeAn instruction on how the activity should be launched. There are five modes that work in conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what should happen when the activity is called upon to handle an intent. They are:

"standard"
"singleTop"
"singleTask"
"singleInstance"
"singleInstancePerTask"

The default mode is "standard".

As shown in the table below, the modes fall into two main groups, with "standard" and "singleTop" activities on one side, and "singleTask", "singleInstance", and "singleInstancePerTask" activities on the other. An activity with the "standard" or "singleTop" launch mode can be instantiated multiple times. The instances can belong to any task and can be located anywhere in the activity task. Typically, they're launched into the task that called startActivity() (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK instruction, in which case a different task is chosen — see the taskAffinity attribute).

In contrast, "singleTask", "singleInstance", and "singleInstancePerTask" activities have different behaviors. "singleInstancePerTask" is always at the root of the activity task. Moreover, the device can hold only one instance of the "singleInstance" activity at a time, while the "singleInstancePerTask activity can be instantiated multiple times in different tasks when FLAG_ACTIVITY_MULTIPLE_TASK or FLAG_ACTIVITY_NEW_DOCUMENT is set. An activity with the “singleTask" launch mode combines the behaviors of "singleInstance" and "singleInstancePerTask": the activity can be instantiated multiple times and can be located anywhere in a task of the same taskAffinity. Meanwhile, the device can only hold one task for locating the “singleTask" activity at the root of the activity task.

The "standard" and "singleTop" modes differ from each other in just one respect: Every time there's a new intent for a "standard" activity, a new instance of the class is created to respond to that intent. Each instance handles a single intent. Similarly, a new instance of a "singleTop" activity may also be created to handle a new intent. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.

Similarly, if you navigate up to an activity on the current stack, the behavior is determined by the parent activity's launch mode. If the parent activity has launch mode singleTop (or the up intent contains FLAG_ACTIVITY_CLEAR_TOP), the parent is brought to the top of the stack, and its state is preserved. The navigation intent is received by the parent activity's onNewIntent() method. If the parent activity has launch mode standard (and the up intent does not contain FLAG_ACTIVITY_CLEAR_TOP), the current activity and its parent are both popped off the stack, and a new instance of the parent activity is created to receive the navigation intent.

The "singleInstance" mode also differs from "singleTask" and "singleInstancePerTask" in only one respect: an activity with the "singleTask" or "singleInstancePerTask” launch mode allows other activities (necessarily "standard" and "singleTop" activities) to be part of its task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task; it must be the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.

Use CasesLaunch ModeMultiple Instances?Comments
Normal launches for most activities "standard" Yes Default. The system always creates a new instance of the activity in the target task and routes the intent to it.
"singleTop" Conditionally If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
Specialized launches
(not recommended for general use)
"singleTask" Conditionally The system creates the activity at the root of a new task or locates the activity on an existing task with the same affinity. If an instance of the activity already exists and is at the root of the task, the system routes the intent to existing instance through a call to its onNewIntent() method, rather than creating a new one.
"singleInstance" No Same as "singleTask", except that the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task.
"singleInstancePerTask" Conditionally The activity can only be running as the root activity of the task, the first activity that created the task, and therefore there will only be one instance of this activity in a task; but activity can be instantiated multiple times in different tasks.

As shown in the table above, standard is the default mode and is appropriate for most types of activities. SingleTop is also a common and useful launch mode for many types of activities. The other modes — singleTask , singleInstance, and singleInstancePerTask — are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications.

Regardless of the launch mode that you choose, make sure to test the usability of the activity during launch and when navigating back to it from other activities and tasks using the Back button.

For more information on launch modes and their interaction with Intent flags, see the Tasks and Back Stack document.

android:lockTaskModeDetermines how the system presents this activity when the device is running in lock task mode.

Android can run tasks in an immersive, kiosk-like fashion called lock task mode. When the system runs in lock task mode, device users typically can’t see notifications, access non-allowlisted apps, or return to the home screen (unless the Home app is allowlisted). Only apps that have been allowlisted by a device policy controller (DPC) can run when the system is in lock task mode. System and privileged apps, however, can run in lock task mode without being allowlisted.

The value can be any one of the following R.attr.lockTaskMode string values:

ValueDescription
"normal" Default value. This is the default value. Tasks don't launch into lock task mode but can be placed there by calling startLockTask().
"never"

Tasks don't launch into lockTask mode, and the device user can't pin these tasks from the overview screen.

Note: This mode is only available to system and privileged applications. Non-privileged apps with this value are treated as normal.

"if_whitelisted" If the DPC authorizes this package using DevicePolicyManager.setLockTaskPackages(), then this mode is identical to always, except that the activity needs to call stopLockTask() before being able to finish if it is the last locked task. If the DPC does not authorize this package then this mode is identical to normal.
"always"

Tasks rooted at this activity always launch into lock task mode. If the system is already in lock task mode when this task is launched then the new task are launched on top of the current task. Tasks launched in this mode can exit lock task mode by calling finish().

Note: This mode is only available to system and privileged applications. Non-privileged apps with this value are treated as normal.

This attribute was introduced in API Level 23.

android:maxRecentsThe maximum number of tasks rooted at this activity in the overview screen. When this number of entries is reached, the system removes the least-recently used instance from the overview screen. Valid values are 1 through 50 (25 on low memory devices); zero is invalid. This must be an integer value, such as 50. The default value is 16. android:maxAspectRatio

The maximum aspect ratio the activity supports. If the app runs on a device with a wider aspect ratio, the system automatically letterboxes the app, leaving portions of the screen unused so the app can run at its specified maximum aspect ratio.

Maximum aspect ratio is expressed as the decimal form of the quotient of the device's longer dimension divided by its shorter dimension. For example, if the maximum aspect ratio is 7:3, set the value of this attribute to 2.33.

On non-wearable devices, the value of this attribute needs to be 1.33 or greater. On wearable devices, it must be 1.0 or greater. Otherwise, the system ignores the set value.

Note: This attribute is ignored if the activity has resizeableActivity set to true, since that means your activity supports any size.

For more information about this attribute, see Declare a maximum aspect ratio in Declare restricted screen support.

android:multiprocessWhether an instance of the activity can be launched into the process of the component that started it — "true" if it can be, and "false" if not. The default value is "false".

Normally, a new instance of an activity is launched into the process of the application that defined it, so all instances of the activity run in the same process. However, if this flag is set to "true", instances of the activity can run in multiple processes, allowing the system to create instances wherever they are used (provided permissions allow it), something that is almost never necessary or desirable.

android:nameThe name of the class that implements the activity, a subclass of Activity. The attribute value should be a fully qualified class name (such as, "com.example.project.ExtracurricularActivity"). However, as a shorthand, if the first character of the name is a period (for example, ".ExtracurricularActivity"), it is appended to the namespace specified in the build.gradle file.

Once you publish your application, you should not change this name (unless you've set android:exported="false").

There is no default. The name must be specified.

android:noHistoryWhether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false".

A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it. In this case, onActivityResult() is never called if you start another activity for a result from this activity.

This attribute was introduced in API Level 3.

android:parentActivityNameThe class name of the logical parent of the activity. The name here must match the class name given to the corresponding <activity> element's android:name attribute.

The system reads this attribute to determine which activity should be started when the user presses the Up button in the action bar. The system can also use this information to synthesize a back stack of activities with TaskStackBuilder.

To support API levels 4 - 16, you can also declare the parent activity with a <meta-data> element that specifies a value for "android.support.PARENT_ACTIVITY". For example:

<activity
    android:name="com.example.app.ChildActivity"
    android:label="@string/title_child_activity"
    android:parentActivityName="com.example.app.MainActivity" >
    <!-- Parent activity meta-data to support API level 4+ -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.example.app.MainActivity" />
</activity>

For more information about declaring the parent activity to support Up navigation, read Providing Up Navigation.

This attribute was introduced in API Level 16.

android:persistableMode

Defines how an instance of an activity is preserved within a containing task across device restarts.

If the root activity of a task sets this attribute's value to persistRootOnly, then only the root activity is preserved. Otherwise, the activities that are higher up the task's back stack are examined; any of these activities that set this attribute's value to persistAcrossReboots are preserved.

If you use this attribute, you must set its value to one of the following:

ValueDescription
persistRootOnly Default value. When the system restarts, the activity task is preserved, but only the root activity's launching intent is used.

When your app's launching intent loads your app's root activity, the activity doesn't receive a PersistableBundle object. Therefore, don't use onSaveInstanceState() to preserve the state of your app's root activity across a device restart.

Note: This attribute value affects your app's behavior only if it's set on your app's root activity.

persistAcrossReboots

This activity's state is preserved, along with the state of each activity higher up the back stack that has its own persistableMode attribute set to persistAcrossReboots. If an activity doesn't have a persistableMode attribute that is set to persistAcrossReboots, or if it's launched using the Intent.FLAG_ACTIVITY_NEW_DOCUMENT flag, then that activity, along with all activities higher up the back stack, aren't preserved.

When an intent loads an activity whose persistableMode attribute is set to persistAcrossReboots in your app, the activity receives a PersistableBundle object in its onCreate() method. Therefore, you can use onSaveInstanceState() to preserve the state of an activity across a device restart as long as its persistableMode attribute is set to persistAcrossReboots.

Note: This attribute value affects your app's behavior even if it's set on an activity other than your app's root activity.

persistNever

The activity's state isn't preserved.

Note: This attribute value affects your app's behavior only if it's set on your app's root activity.

This attribute was introduced in API level 21.

android:permissionThe name of a permission that clients must have to launch the activity or otherwise get it to respond to an intent. If a caller of startActivity() or startActivityForResult() has not been granted the specified permission, its intent will not be delivered to the activity.

If this attribute is not set, the permission set by the <application> element's permission attribute applies to the activity. If neither attribute is set, the activity is not protected by a permission.

For more information on permissions, see the Permissions section in the introduction and another document, Security and Permissions.

android:processThe name of the process in which the activity should run. Normally, all components of an application run in a default process name created for the application and you do not need to use this attribute. But if necessary, you can override the default process name with this attribute, allowing you to spread your app components across multiple processes.

If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it's needed and the activity runs in that process. If the process name begins with a lowercase character, the activity will run in a global process of that name, provided that it has permission to do so. This allows components in different applications to share a process, reducing resource usage.

The <application> element's process attribute can set a different default process name for all components.

android:relinquishTaskIdentityWhether or not the activity relinquishes its task identifiers to an activity above it in the task stack. A task whose root activity has this attribute set to "true" replaces the base Intent with that of the next activity in the task. If the next activity also has this attribute set to "true" then it will yield the base Intent to any activity that it launches in the same task. This continues for each activity until an activity is encountered which has this attribute set to "false". The default value is "false".

This attribute set to "true" also permits the activity's use of the ActivityManager.TaskDescription to change labels, colors and icons in the overview screen.

resizeableActivity

Specifies whether the app supports multi-window mode. You can set this attribute in either the <activity> or <application> element.

If you set this attribute to true, the user can launch the activity in split-screen and free-form modes. If you set the attribute to false, the app can't be tested or optimized for a multi-window environment. The system could still put the activity in multi-window mode with compatibility mode applied. Setting this attribute to true also doesn't guarantee that there will be no other apps in multi-window mode visible on screen (such as picture-in-picture) or on other displays. Therefore, setting this flag does not ensure that your app has exclusive resource access.

If your app targets API level 24 or higher, but you do not specify a value for this attribute, the attribute's value defaults to true.

If your app targets API level 31 or higher, this attribute works differently on small and large screens:

  • Large screens (sw >= 600dp): All apps support multi-window mode. The attribute indicates whether an app can be resized (not whether the app supports multi-window mode). If resizeableActivity="false", the app is put into compatibility mode when necessary to conform to display dimensions.
  • Small screens (sw < 600dp): If resizeableActivity="true" and the minimum width and minimum height of the activity are within the multi-window requirements, the app supports multi-window mode. If resizeableActivity="false", the app does not support multi-window mode regardless of the activity minimum width and height.

Note: Device manufacturers can override the API level 31 behavior.

This attribute was added in API level 24.

Note: A task's root activity value is applied to all additional activities launched in the task. That is, if the root activity of a task is resizable then the system treats all other activities in the task as resizable. If the root activity is not resizable, the other activities in the task are not resizable.

android:screenOrientationThe orientation of the activity's display on the device. The system ignores this attribute if the activity is running in multi-window mode.

The value can be any one of the following strings:

"unspecified" The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
"behind" The same orientation as the activity that's immediately beneath it in the activity stack.
"landscape" Landscape orientation (the display is wider than it is tall).
"portrait" Portrait orientation (the display is taller than it is wide).
"reverseLandscape" Landscape orientation in the opposite direction from normal landscape. Added in API level 9.
"reversePortrait" Portrait orientation in the opposite direction from normal portrait. Added in API level 9.
"sensorLandscape" Landscape orientation, but can be either normal or reverse landscape based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. Added in API level 9.
"sensorPortrait" Portrait orientation, but can be either normal or reverse portrait based on the device sensor. The sensor is used even if the user has locked sensor-based rotation. Added in API level 9.
"userLandscape" Landscape orientation, but can be either normal or reverse landscape based on the device sensor and the user's preference. Added in API level 18.
"userPortrait" Portrait orientation, but can be either normal or reverse portrait based on the device sensor and the user's preference. Added in API level 18.
"sensor" The orientation is determined by the device orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device. Some devices, though, will not rotate to all four possible orientations, by default. To allow all four orientations, use "fullSensor" The sensor is used even if the user locked sensor-based rotation.
"fullSensor" The orientation is determined by the device orientation sensor for any of the 4 orientations. This is similar to "sensor" except this allows any of the 4 possible screen orientations, regardless of what the device will normally do (for example, some devices won't normally use reverse portrait or reverse landscape, but this enables those). Added in API level 9.
"nosensor" The orientation is determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device.
"user" The user's current preferred orientation.
"fullUser" If the user has locked sensor-based rotation, this behaves the same as user, otherwise it behaves the same as fullSensor and allows any of the 4 possible screen orientations. Added in API level 18.
"locked" Locks the orientation to its current rotation, whatever that is. Added in API level 18.

Note: When you declare one of the landscape or portrait values, it is considered a hard requirement for the orientation in which the activity runs. As such, the value you declare enables filtering by services such as Google Play so your application is available only to devices that support the orientation required by your activities. For example, if you declare either "landscape", "reverseLandscape", or "sensorLandscape", then your application will be available only to devices that support landscape orientation. However, you should also explicitly declare that your application requires either portrait or landscape orientation with the <uses-feature> element. For example, <uses-feature android:name="android.hardware.screen.portrait"/>. This is purely a filtering behavior provided by Google Play (and other services that support it) and the platform itself does not control whether your app can be installed when a device supports only certain orientations.

android:showForAllUsers

Whether or not the activity is shown when the device's current user is different than the user who launched the activity. You can set this attribute to a literal value—"true" or "false"—or you can set the attribute to a resource or theme attribute that contains a boolean value.

This attribute was added in API level 23.

android:stateNotNeededWhether or not the activity can be killed and successfully restarted without having saved its state — "true" if it can be restarted without reference to its previous state, and "false" if its previous state is required. The default value is "false".

Normally, before an activity is temporarily shut down to save resources, its onSaveInstanceState() method is called. This method stores the current state of the activity in a Bundle object, which is then passed to onCreate() when the activity is restarted. If this attribute is set to "true", onSaveInstanceState() may not be called and onCreate() will be passed null instead of the Bundle — just as it was when the activity started for the first time.

A "true" setting ensures that the activity can be restarted in the absence of retained state. For example, the activity that displays the home screen uses this setting to make sure that it does not get removed if it crashes for some reason.

supportsPictureInPicture

Specifies whether the activity supports Picture-in-Picture display.

This attribute was added in API level 24.

android:taskAffinityThe task that the activity has an affinity for. Activities with the same affinity conceptually belong to the same task (to the same "application" from the user's perspective). The affinity of a task is determined by the affinity of its root activity.

The affinity determines two things — the task that the activity is re-parented to (see the allowTaskReparenting attribute) and the task that will house the activity when it is launched with the FLAG_ACTIVITY_NEW_TASK flag.

By default, all activities in an application have the same affinity. You can set this attribute to group them differently, and even place activities defined in different applications within the same task. To specify that the activity does not have an affinity for any task, set it to an empty string.

If this attribute is not set, the activity inherits the affinity set for the application (see the <application> element's taskAffinity attribute). The name of the default affinity for an application is the namespace set in the build.gradle file.

android:themeA reference to a style resource defining an overall theme for the activity. This automatically sets the activity's context to use this theme (see setTheme(), and may also cause "starting" animations prior to the activity being launched (to better match what the activity actually looks like).

If this attribute is not set, the activity inherits the theme set for the application as a whole — from the <application> element's theme attribute. If that attribute is also not set, the default system theme is used. For more information, see the Styles and Themes developer guide.

android:uiOptionsExtra options for an activity's UI.

Must be one of the following values.

ValueDescription
"none" No extra UI options. This is the default.
"splitActionBarWhenNarrow" Add a bar at the bottom of the screen to display action items in the app bar (also known as the action bar), when constrained for horizontal space (such as when in portrait mode on a handset). Instead of a small number of action items appearing in the app bar at the top of the screen, the app bar is split into the top navigation section and the bottom bar for action items. This ensures a reasonable amount of space is made available not only for the action items, but also for navigation and title elements at the top. Menu items are not split across the two bars; they always appear together.

For more information about the app bar, see the Adding the App Bar training class.

This attribute was added in API level 14.

android:windowSoftInputModeHow the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:
  • The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
  • The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. Individual values are separated by a vertical bar (|). For example:

<activity android:windowSoftInputMode="stateVisible|adjustResize" ... >

Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the theme.

ValueDescription
"stateUnspecified" The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme.

This is the default setting for the behavior of the soft keyboard.

"stateUnchanged" The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore. "stateHidden" The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. "stateAlwaysHidden" The soft keyboard is always hidden when the activity's main window has input focus. "stateVisible" The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. "stateAlwaysVisible" The soft keyboard is visible when the window receives input focus. "adjustUnspecified" It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the current focus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area.

This is the default setting for the behavior of the main window.

"adjustResize" The activity's main window is always resized to make room for the soft keyboard on screen. "adjustPan" The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

This attribute was introduced in API Level 3.

introduced in:API Level 1 for all attributes except for noHistory and windowSoftInputMode, which were added in API Level 3.see also:<application>
<activity-alias>

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2022-09-07 UTC.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]