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 android:allowTaskReparenting Whether 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
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 android:alwaysRetainTaskState Whether 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 " android:autoRemoveFromRecents Whether 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:banner A 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 This attribute must be set as a reference to a drawable resource containing the image (for
example See Provide a home screen banner in Get Started with TV Apps for more information. android:clearTaskOnLaunch Whether 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 " 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 " If this attribute and This attribute is ignored if 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 android:configChanges Lists
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 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 '
All of these configuration changes can impact the resource values seen by the application. Therefore, when Note: To handle all Multi-Window related configuration changes use both 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 android:documentLaunchMode Specifies 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:
Note: For values other than " android:enabled Whether 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 android:excludeFromRecents Whether 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:exported This element sets whether the activity can be launched by components of other applications:
If an activity in your app includes intent filters, set this element to "
If this element is set to " 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 android:finishOnTaskLaunch Whether 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 This attribute is ignored if android:hardwareAccelerated Whether 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:icon An 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 The activity's icon — whether set here or by the android:immersive Sets 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:label A 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 The activity's label — whether set here or by the 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:launchMode An
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: " The default mode is " As shown in the table below, the modes fall into two main groups, with " In contrast, " The " 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 The "
As shown in the table above, 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:lockTaskMode Determines 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
This attribute was introduced in API Level 23. android:maxRecents The 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 For more information about this attribute, see Declare a maximum aspect ratio in Declare restricted screen support. android:multiprocess Whether 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 " android:name The 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 There is no default. The name must be specified. android:noHistory Whether or not the activity should be removed from the activity stack and finished (its 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 " This attribute was introduced in API Level 3. android:parentActivityName The 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 To support API levels 4 - 16, you can
also declare the parent activity with a <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 If you use this attribute, you must set its value to one of the following:
This attribute was introduced in API level 21. android:permission The 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 or 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 For more information on permissions, see the Permissions section in the introduction and another document, Security and Permissions. android:process The 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 android:relinquishTaskIdentity Whether 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 " resizeableActivity Specifies whether the app supports multi-window mode. You can set this attribute in either the 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:
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:screenOrientation The 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:
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 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— This attribute was added in API level 23. android:stateNotNeeded Whether 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 A " supportsPictureInPicture Specifies whether the activity supports Picture-in-Picture display. This attribute was added in API level 24. android:taskAffinity The 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 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 android:theme A reference to a style resource defining an overall theme for the
activity. This automatically sets the activity's context to use this theme (see , 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 android:uiOptions Extra options for an activity's UI. Must be one of the following values.
For more information about the app bar, see the Adding the App Bar training class. This attribute was added in API level 14. android:windowSoftInputMode How 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 setting must be one of the values listed in the following table, or a combination of one " <activity android:windowSoftInputMode="stateVisible|adjustResize" ... > Values set here (other than "
This attribute was introduced in API Level 3. introduced in:API Level 1 for all attributes except fornoHistory 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" }] |