天天看點

<activity>

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:configChanges=["mcc", "mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "screenLayout", "fontScale",
                                 "uiMode", "orientation", "screenSize",
                                 "smallestScreenSize"]
          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:label="string resource"
          android:launchMode=["multiple" | "singleTop" |
                              "singleTask" | "singleInstance"]
          android:maxRecents="integer"
          android:multiprocess=["true" | "false"]
          android:name="string"
          android:noHistory=["true" | "false"]  
          android:parentActivityName="string" 
          android:permission="string"
          android:process="string"
          android:relinquishTaskIdentity=["true" | "false"]
          android:screenOrientation=["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]
          android:stateNotNeeded=["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>

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: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 

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: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 "

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: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 

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 Banners in the UI Patterns for TV design guide, and 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 "

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 orHome 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) were removed when the user pressed Homeand the task went to the background. So the user sees 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.

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

onConfigurationChanged()

 method is called.

Note: Using this attribute should be avoided and used only as a last resort. Please read Handling Runtime Changes for more information about how to properly handle a restart due to a configuration change.

Any or all of the following strings are valid values for this attribute. Multiple values are separated by '

|

' — for example, "

locale|navigation|orientation

".
Value Description
"

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.
"

locale

"
The locale has changed — the user has selected a new language that text should be displayed in.
"

touchscreen

"
The touchscreen has changed. (This should never normally happen.)
"

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.
"

navigation

"
The navigation type (trackball/dpad) has changed. (This should never normally happen.)
"

screenLayout

"
The screen layout has changed — this might be caused by a different display being activated.
"

fontScale

"
The font scaling factor has changed — the user has selected a new global font size.
"

uiMode

"
The user interface mode has changed — this can be caused when the user places the device into a desk/car dock or when the night mode changes. See 

UiModeManager

. Added in API level 8.
"

orientation

"

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

Note: If your application targets API level 13 or higher (as declared by the 

minSdkVersion

 and 

targetSdkVersion

attributes), then you should also declare the 

"screenSize"

configuration, because it also changes when a device switches between portrait and landscape orientations.
"

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. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

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. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

Added in API level 13.

"

layoutDirection

"
The layout direction has changed. For example, changing from left-to-right (LTR) to right-to-left (RTL). Added in API level 17.
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.

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:

Value Description
"

intoExisting

"
The activity reuses the existing task for the document. Using this value is the same as setting the 

FLAG_ACTIVITY_NEW_DOCUMENT

 flag, withoutsetting the 

FLAG_ACTIVITY_MULTIPLE_TASK

 flag, as described in Using the Intent flag to add a 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: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 

<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: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

Whether or not the activity can be launched by components of other applications — "

true

" if it can be, and "

false

" if not. If "

false

", the activity can be launched only by components of the same application or applications with the same user ID.

The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "

false

". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "

true

".

This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the external entities that can invoke the activity (see the 

permission

attribute).

android:finishOnTaskLaunch

Whether or not an existing instance of the activity should be shut down (finished) 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.

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 

<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: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

<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:launchMode

An instruction on how the activity should be launched. There are four 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

"

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

" and "

singleInstance

" 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 stack. 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

" and "

singleInstance

" activities can only begin a task. They are always at the root of the activity stack. Moreover, the device can hold only one instance of the activity at a time — only one such 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 "

singleTask

" and "

singleInstance

" modes also differ from each other in only one respect: A "

singleTask

" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "

standard

" and "

singleTop

" activities) can be launched into that task. A "

singleInstance

" activity, on the other hand, permits no other activities to be part of its task. It's 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 Cases Launch Mode Multiple 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

"
No The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, 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.
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

 and 

singleInstance

 — 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: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: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 "

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: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 package name specified in the 

<manifest>

 element.

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:noHistory

Whether 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: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 

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.myfirstapp.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: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 

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: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 

<application>

 element's 

process

 attribute can set a different default process name for all components.

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 "

true

" also permits the activity's use of the

ActivityManager.TaskDescription

 to change labels, colors and icons in the overview screen.

android:screenOrientation

The orientation of the activity's display on the device.

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. Added in API level 9.
"

sensorPortrait

"
Portrait orientation, but can be either normal or reverse portrait based on the device sensor. 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 sensor preference. If the user has locked sensor-based rotation, this behaves the same as

landscape

, otherwise it behaves the same as 

sensorLandscape

.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 sensor preference. If the user has locked sensor-based rotation, this behaves the same as 

portrait

, otherwise it behaves the same as 

sensorPortrait

. 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"

.
"

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. Except for this distinction, the system chooses the orientation using the same policy as for the "

unspecified

" setting.
"

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: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

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.

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

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 package name set by the 

<manifest>

 element.

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 

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:uiOptions

Extra options for an activity's UI.

Must be one of the following values.

Value Description

"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: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 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.
Value Description
"

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 visible when that's normally appropriate (when the user is navigating forward to the activity's main window).
"

stateAlwaysVisible

"
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.
"

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>

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:configChanges=["mcc", "mnc", "locale",
                                 "touchscreen", "keyboard", "keyboardHidden",
                                 "navigation", "screenLayout", "fontScale",
                                 "uiMode", "orientation", "screenSize",
                                 "smallestScreenSize"]
          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:label="string resource"
          android:launchMode=["multiple" | "singleTop" |
                              "singleTask" | "singleInstance"]
          android:maxRecents="integer"
          android:multiprocess=["true" | "false"]
          android:name="string"
          android:noHistory=["true" | "false"]  
          android:parentActivityName="string" 
          android:permission="string"
          android:process="string"
          android:relinquishTaskIdentity=["true" | "false"]
          android:screenOrientation=["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]
          android:stateNotNeeded=["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>

可以包含:

<意圖過濾器> 

<中繼資料>

描述:
聲明的活性(一個

活動

實作應用程式的可視化使用者界面的一部分的子類)。所有活動必須由代表

<活動>

在manifest檔案中的元素。任何未聲明的存在将不會被系統中可以看出,将永遠不會被執行。
屬性:

機器人:allowEmbedded

表明該活動可以推出,另一個活動的嵌入式孩子。特别是在孩子生活在一個容器中,如由其他活動所擁有的顯示情況。例如,用于磨損自定義通知的活動必須申報本這樣穿可以顯示活動在它的範圍内流,它駐留在另一個程序。

此屬性的預設值是

假的

機器人:allowTaskReparenting

是否該活動可以從它開始有當該任務被旁邊帶到前面為具有親和性的任務的任務移動- “ 

 ”,如果它可以移動,而“ 

 ”,如果它必須保持與任務在那裡開始。

如果沒有設定該屬性,通過相應設定的值 

allowTaskReparenting

 的屬性

<應用>

元素适用于行為。預設值是“ 

 ”。

通常,當一個活動開始時,它與啟動它的活動的任務相關聯,并且它保持有在其整個生命周期。您可以使用此屬性,迫使它重新向父它時将不再顯示其目前任務具有親和力的任務。通常情況下,它用來使一個應用程式的活動移動到與該應用程式相關聯的主要任務。

例如,如果一封郵件包含一個連結到一個網頁,點選連結帶來了可以顯示的頁面的活動。該活動是由浏覽器應用程式中定義,但在啟動的電子郵件任務的一部分。如果它被重設父到浏覽器的任務,它會顯示在浏覽器旁邊說到前面,将缺席時,電子郵件任務再次挺身而出。

一個活動的親和力是由定義 

taskAffinity

屬性。任務的親和力是通過讀取它的根活動的親和性來确定。是以,根據定義,一個根活動總是與相同的親和力的任務。自從“活動

singleTask

 ”或“

singleInstance

 ”啟動模式隻能在一個任務,再為人父母的根僅限于“ 

标準

 ”和“ 

singleTop

 ”模式。(參見

launchMode

 屬性。)

機器人:alwaysRetainTaskState

“ -不論該活性是在任務的狀态将總是由系統維持

 ”,如果它會,而“ 

 ”,如果系統被允許任務複位到它的初始狀态在某些情況下。預設值是“ 

 ”。此屬性是隻為任務的根系活力有意義的; 它忽略了所有其他活動。

通常情況下,系統會清除任務(從堆棧中删除根系活力上述所有活動)在某些情況下,當使用者重新選擇從主螢幕上的任務。通常情況下,如果使用者沒有通路過的任務要一定的時間,例如30分鐘這樣做。

然而,當這個屬性為“ 

 ”,使用者将總是傳回任務在其最後的狀态,無論他們如何到達那裡。這是有用的,例如,在使用者的Web浏覽器,其中有很多國家(如多個打開的頁籤)的應用程式,使用者都不會喜歡輸。

機器人:autoRemoveFromRecents

通過活動,此屬性推出與否任務保留在  總覽畫面,直到在任務的最後一個活動完成。如果

屬實

,任務自動從總覽畫面中删除。這将覆寫調用者的使用 

FLAG_ACTIVITY_RETAIN_IN_RECENTS

。它必須是一個布爾值,無論是“ 

 ”或“ 

 ”。

機器人:旗幟

一個 繪制資源 提供與其相關的項目擴充的圖形化的一面旗幟。與使用 

<活動>

标簽來提供一個預設的旗幟特定活動,或與 

<應用程式>

 标記為所有應用程式提供活動的一面旗幟。

該系統使用的旗幟,代表在Android的電視主螢幕的應用程式。由于該橫幅僅在主螢幕上顯示出來,它隻能通過與處理的活動應用程式指定 

CATEGORY_LEANBACK_LAUNCHER

意圖。

此屬性必須設定為包含圖像(例如,繪制資源的引用

“@繪制/旗幟”

)。沒有預設的旗幟。

見 橫幅為電視設計的指導UI模式,并 提供一個主螢幕的旗幟在擷取與電視應用程式啟動以擷取更多資訊。

機器人:clearTaskOnLaunch

是否所有的活動都會從任務中删除,除根系活力,無論是從主螢幕上再次推出- “ 

 ”如果任務總是剝離下來到其根系活力,而“ 

 ”,如果不。預設值是“ 

 ”。此屬性僅對啟動一個新的任務(根活性)的活動是有意義; 它忽略了任務中的所有其他活動。

當值是“ 

 ”,每當使用者再次啟動任務,他們被帶到其根系活力,無論他們上一次在做任務,無論他們是否使用後退或首頁按鈕離開它。當該值是“ 

 ”時,任務可以在某些情況下,活動(見清零

alwaysRetainTaskState

屬性),但并非總是如此。

舉個例子,有人從主螢幕啟動的活動P,并從那裡進入活動問 ​​:使用者下次按下首頁,然後傳回到活動P.通常情況下,使用者将看到活動Q,因為這是他們上次做P中的任務。然而,若P設定這個标志為“ 

”時,所有的活動在它(Q在這種情況下)頂除去,當使用者按壓 首頁和任務去了背景。是以使用者傳回到任務時隻能看到P上。

如果該屬性與

allowTaskReparenting

 都是“ 

 ”,任何可以活動重新與父母被移到它們共享具有親和性的任務; 然後将剩餘的活動下降,如上所述。

機器人:configChanges

列出配置更改活動将處理本身。當配置在運作時改變時,該活動被關閉,預設情況下重新啟動,但在宣布的配置與此屬性将阻止重新啟動該活動。相反,該活動仍在運作和

onConfigurationChanged()

方法被調用。

注意:使用這個屬性應避免與隻能作為最後的手段。請閱讀處理運作時更改有關如何正确處理重新開機更多資訊由于配置改變。

任何或所有下列字元串是該屬性的有效值。多個值之間用“ 

|

 ” -例如,“ 

區域|網站導航|方向

 ”。
描述
“ 

MCC

 ”
IMSI的移動國家代碼(MCC)已經改變 - SIM卡已被檢測和更新的MCC。
“ 

MNC

 ”
IMSI的移動網絡代碼(MNC)已經改變 - 一個SIM卡已被檢測并更新MNC。
“ 

語言環境

 ”
語言環境已經改變 - 使用者選擇文本應顯示在一個新的語言。
“ 

觸摸屏

 ”
觸摸屏已經改變。(這不應該發生正常。)
“ 

鍵盤

 ”
鍵盤類型已經改變 - 例如,使用者已在外部鍵盤堵塞。
“ 

keyboardHidden

 ”
鍵盤輔助改變 - 例如,使用者已經表明的硬體鍵盤。
“ 

導航

 ”
導航型(軌迹球/ DPAD)發生了變化。(這不應該發生正常。)
“ 

螢幕布置

 ”
螢幕布局改變 - 這可能是由不同的顯示被激活而引起的。
“ 

fontScale

 ”
字型縮放系數已改變 - 使用者已經選擇了一個新的全局字型大小。
“ 

uiMode

 ”
使用者界面模式發生了變化-當使用者把裝置插入台/車停靠時或夜間模式的變化這是可以引起的。見

UiModeManager

。 在API級别8。
“ 

方向

 ”

螢幕的方向發生了變化 - 使用者旋轉裝置。

注意:如果您的應用程式面向API級别13或更高版本(由申報

的minSdkVersion

targetSdkVersion

屬性),那麼你也應該申報

“螢幕尺寸”

 的配置,因為它也改變縱向和橫向之間在裝置的開關。
“ 

螢幕大小

 ”

目前可用的螢幕大小發生了變化。這代表了目前可用的尺寸,相對于目前縱橫比的變化,是以,當使用者在橫向和縱向之間切換将發生變化。但是,如果你的應用程式面向API級别12或更低,那麼你的活動總是處理此配置變化本身(在Android 3.2或更高版本的裝置上運作時,此配置更改不會重新啟動您的活動,甚至)。

在API級别13。

smallestScreenSize

實體螢幕尺寸發生了變化。這代表了尺寸的變化,無論取向的,是以,當實際實體螢幕尺寸已經改變,例如切換到外部顯示将隻改變。這種結構的改變對應于一個變化 最小寬度配置。但是,如果你的應用程式面向API級别12或更低,那麼你的活動總是處理此配置變化本身(在Android 3.2或更高版本的裝置上運作時,此配置更改不會重新啟動您的活動,甚至)。

在API級别13。

“ 

的layoutDirection

布局方向已經改變。例如,更改左到右(LTR)為從右到左(RTL)。在API級别17。
所有的這些配置的變化可以影響由應用程式看到的資源值。是以,當

onConfigurationChanged()

被調用時,它通常會需要再次檢索所有的資源(包括視圖的布局,圖形等)正确處理的變化。

機器人:documentLaunchMode

指定如何活動的一個新執行個體應該每次啟動時間被添加到一個任務。此屬性允許使用者從同一應用程式的多個檔案出現在 總覽畫面。

它的屬性産生當使用者打開與應用程式的文檔以下效果四個值:

描述

intoExisting

活動重用文檔的現有任務。使用此值是相同的設定

FLAG_ACTIVITY_NEW_DOCUMENT

标志,而不設定

FLAG_ACTIVITY_MULTIPLE_TASK

标志,具體說明 使用意圖示志添加任務 。
“ 

總是

 ”
的活動建立的文檔的新的任務,即使文檔已打開。這是相同的同時設定

FLAG_ACTIVITY_NEW_DOCUMENT

 和

FLAG_ACTIVITY_MULTIPLE_TASK

标志。
“ 

 ”
活動不建立活動的新任務。這是預設值,這就造成隻有當一個新的任務

FLAG_ACTIVITY_NEW_TASK

設定。總覽畫面對待活動,因為它會預設為:它顯示的應用程式,這無論從任何活動恢複最後調用使用者的單個任務。
“ 

從來沒有

 ”
此活動不射入即使意圖包含一個新的文檔 

FLAG_ACTIVITY_NEW_DOCUMENT

。設定此覆寫的行為

FLAG_ACTIVITY_NEW_DOCUMENT

FLAG_ACTIVITY_MULTIPLE_TASK

标志,如果這些在活動設定,并概述螢幕顯示的應用程式,這無論從任何活動恢複最後調用使用者的單個任務。
注:對于不是“價值

 ”和“ 

從不

 ”活動必須被定義

launchMode =“标準”

。如果未指定此屬性,

documentLaunchMode =“無”

使用。

機器人:啟用

-無論是否在活動可以由系統執行個體化 

“真”

,如果它可以是,以及“ 

 ”,如果沒有。預設值是“ 

”。

<應用程式> 

元素都有自己的

啟用

 适用于所有應用程式元件,包括活動屬性。在 

<應用>

 和

<活動>

屬性必須都是“ 

,以便系統能夠執行個體化活動”(因為它們都是由預設值)。如果任一為“ 

”時,它不能被執行個體化。 

機器人:excludeFromRecents

不管是不是通過這個活動發起的任務應該被排除在最近使用的應用程式,在清單中  一覽螢幕。也就是說,當這個活動是一個新任務的根系活力,這個屬性決定任務是否不應該出現在最近的應用程式清單。設定“ 

 ”,如果該任務應 排除在名單; 設定“ 

 ”,如果它應該被 納入。預設值是“ 

 ”。

機器人:出口

是否活性可以通過其他應用程式的元件來啟動- “ 

 ”,如果它可以是,以及“ 

 ”,如果沒有。如果“ 

 ”,則活性可僅由相同的應用程式或應用程式具有相同的使用者ID的部件推出。

預設值取決于活動是否包含意圖過濾器。沒有任何過濾器意味着活動可通過指定确切的類名稱僅調用。這意味着,該活動僅用于應用程式内部使用(因為其他人不知道的類名稱)。是以,在這種情況下,預設值是“ 

 ”。另一方面,至少一個過濾器的存在意味着該活動旨在供外部使用,是以預設值是“ 

 ”。

此屬性是不限制活動接觸到其他應用程式的唯一途徑。還可以使用權限來限制可以調用該活動的外部實體(見 

許可

 屬性)。

機器人:finishOnTaskLaunch

不管是不是活動的現有執行個體,應關閉(完)每當使用者再次啟動它的任務(選擇任務在主螢幕上) - “

 ”,如果它應該關閉,而“ 

 ”如果不是。預設值是“ 

 ”。

如果該屬性與 

allowTaskReparenting

 都是“ 

 ”,該屬性勝過另一個。該活動的親和力被忽略。該活性不重新父,而破壞。

機器人:hardwareAccelerated

“ -不管是不是硬體加速渲染應該為此活動啟用

真正

 ”是否應該被啟用,而“ 

 ”如果不是。預設值是“

 ”。

從Android 3.0的開始,一個硬體加速的OpenGL渲染是提供給應用程式,以提高許多常見的2D圖形操作的性能。當啟用硬體加速渲染器,在帆布,油漆,Xfermode,ColorFilter,Shader和照相機的大部分操作都加速。這将導緻更加平滑的動畫,更流暢滾動,并整體提高了響應,即使應用程式沒有明确使用該架構的OpenGL庫。由于啟用硬體加速所需增加的資源,你的應用程式會消耗更多的記憶體。

注意,并非所有的OpenGL的2D操作的加速。如果啟用硬體加速渲染器,測試應用程式,以確定它可以利用渲染沒有錯誤。

安卓圖示

表示活動的圖示。當需要在螢幕上活動的表示的圖示會顯示給使用者。例如,對于啟動任務的活動圖示顯示在發射視窗。該圖示常伴有标簽(見

機器人:标簽

屬性)。

此屬性必須設定為包含圖像定義的可繪制資源的引用。如果沒有設定,對作為一個整體來代替應用程式指定的圖示(參見 

<應用程式>

 元素的

圖示

屬性)。

活動的圖示-無論在這裡還是由設定 

<應用>

 元素-也是所有活動的意圖過濾器的預設圖示(見 

<意圖過濾器>

元素的 

圖示

屬性)。

機器人:标簽

為活動的使用者可讀的标簽。該标簽顯示在螢幕上活動時必須表示給使用者。它通常與活動圖示一起顯示。

如果沒有設定該屬性,作為一個整體來代替應用程式的标簽集(見

<應用程式>

元素的 

标簽

屬性)。

活動的标簽-無論在這裡還是由設定 

<應用>

元素-也是所有活動的意圖過濾器預設标簽(見 

<意圖過濾器>

元素的 

标簽

屬性)。

标簽應設定為一個字元串資源的引用,以便它可以被本地化一樣在使用者界面的其他串。但是,作為一種友善,而你開發的應用程式,它也可以被設定為一個原始字元串。

機器人:launchMode

上的活動應該如何啟動的指令。有迹象表明,在活動标志(協同工作,四種模式

FLAG_ACTIVITY_ *

常量)

意向

對象,以确定何時活動被要求處理的意圖應該發生什麼。他們是:

“ 

标準

 ” 

“ 

singleTop

 ” 

“ 

singleTask

 ” 

“ 

singleInstance

 ”

預設模式為“ 

标準

 ”。

如下表所示,模式分為兩大組,“ 

标準

 ”和“ 

singleTop

一側”的活動,以及“ 

singleTask

 ”和“

singleInstance

在另一”活動。用“的活性

标準

 ”或“ 

singleTop

 ”發射模式可以被執行個體化多次。執行個體可以屬于任何任務,并可以在活動的堆棧的任何位置。通常情況下,它們發射到調用該任務

startActivity() 

(除非意圖對象包含 

FLAG_ACTIVITY_NEW_TASK

 指令,在這種情況下,選擇不同的任務-參見 taskAffinity屬性)。

與此相反,“ 

singleTask

 ”和“ 

singleInstance

 ”活動才能開始的任務。它們總是在活動堆的根。此外,該裝置可以一次容納隻有一個活動的執行個體-隻有一個這樣的任務。

該“ 

标準

 ”和“ 

singleTop

 ”模式,彼此隻是一個方面不同:每當有一個“新的意圖

标準

 ”活動,建立該類的新執行個體對這一意圖做出回應。每個執行個體處理一個意圖。同樣地,一“的一個新執行個體

singleTop

”活動也可被建立,以處理新的意圖。然而,如果目标任務已經在其堆棧的頂部的活性的現有執行個體,該執行個體将接收新的意圖(在 

onNewIntent()

調用); 不建立一個新的執行個體。在其他情況下-例如,如果“的現有執行個體

singleTop

 ”活動是在目标的任務,而不是在堆棧的頂部,或者如果它是在堆棧的頂部,而不是在所述目标任務-一個新的執行個體會被建立并壓入堆棧。

同樣,如果您 浏覽了目前棧上的活動,該行為是由父活動的啟動模式決定。如果父活動有發射模式

singleTop

(或

向上

意圖包含

FLAG_ACTIVITY_CLEAR_TOP

),父被帶到堆棧的頂部,并且其狀态被保留。導航意圖由父活動的接收

onNewIntent()

 方法。如果父活動有發射模式

标準

(和 

向上

意圖不包含

FLAG_ACTIVITY_CLEAR_TOP

),目前活動及其父均彈出堆棧,并且在建立父活動的新執行個體來接收導航意圖。

在“ 

singleTask

 ”和“ 

singleInstance

 A”:“模式也彼此隻在一個方面有所不同

singleTask

 ”活動允許的其他活動是其任務的一部分。它總是在其工作的根本,而其他活動(不一定是“ 

标準

 ”和“

singleTop

 ”的活動)可以被發射到該任務。A“ 

singleInstance

 ”活動,另一方面,允許沒有其他活動是其任務的一部分。它在任務的唯一活動。如果它開始另一個活動,該活動被配置設定到一個不同的任務-仿佛

FLAG_ACTIVITY_NEW_TASK

在意圖。
用例 啟動模式 多個執行個體? 注釋
對于大多數正常活動啟動 “ 

标準

 ”
預設。系統總是會在目标任務和路線的意圖給它的活動的新執行個體。
“ 

singleTop

 ”
有條件 如果活動的一個執行個體已經存在于目标任務的頂部,系統路由通過其呼叫的意圖,該執行個體

onNewIntent()

方法,而不是建立活動的新執行個體。
專門推出(不推薦用于一般用途) “ 

singleTask

 ”
沒有 系統将建立一個新的任務和路線的意圖,它的根活動。但是,如果活動的一個執行個體已經存在,系統路由意圖通過其呼叫現有執行個體

onNewIntent()

方法,而不是建立一個新的。

singleInstance

沒有 同為“ 

singleTask” 

,所不同的是,系統不發射任何其他的活動進保持該執行個體的任務。活動始終是它的任務單,唯一成員。
如上表中所示,

标準

是預設模式和适用于大多數類型的活動。

SingleTop

也是許多類型的活動,一個共同的和有用的發射模式。其它模式- 

singleTask

singleInstance

 -是 不适合于大多數的應用,因為它們導緻在很可能是不熟悉的使用者,是從其他大多數應用中是非常不同的互動模式。

無論您選擇的發射方式的,請務必在發射過程中,測試活動的可用性和使用其他的活動和任務導航回 ​​到它的時候後退按鈕。

有關啟動模式的詳細資訊和他們的意圖旗幟互動,看到 任務和傳回堆棧 檔案。

機器人:maxRecents

在該此次活動紮根的最大任務數  總覽畫面。當達到此數量的條目,系統将删除概覽螢幕最近最少使用的執行個體。有效值是1到50(25低記憶體裝置上); 零是無效的。這必須是整數值,例如50。預設值是16。

機器人:多程序

是否活動的一個執行個體可以被發射到啟動它的成分的方法- “ 

 ”,如果它可以是,以及“ 

 ”,如果沒有。預設值是“ 

 ”。

通常情況下,一個活動的新執行個體被發射到該定義它的應用程式的過程中,是以在同一程序中運作的活動的所有執行個體。但是,如果該标志被設定為“ 

 ”,活動的執行個體可以在多個程序運作,允許的地方時,它們的系統來建立執行個體(提供權限允許的話),而這是幾乎沒有必要或希望的。

安卓:名稱

實作活動,子類的類的名稱 

活動

。該屬性值應該是一個完全合格的類名(例如,“

com.example.project.ExtracurricularActivity

 ”)。然而,作為一個速記,如果名稱的第一個字元是一個周期(例如,“ 

.ExtracurricularActivity

 ”)時,它被附加到在該指定的包名稱 

<清單>

元素。

一旦你釋出你的應用程式,你應該不會改變這個名字(除非你設定

的android:出口 =“假”

)。

沒有預設值。必須指定名稱。

機器人:noHistory

不管是不是活動應該從活動堆棧被删除,完成(其

完成()

 調用的方法),當使用者導航遠離它,它不再可見螢幕上- “ 

 ”,如果它應該完成,而“ 

 ”如果不。預設值是“ 

 ”。

值“ 

 ”是指該活動不會留下曆史痕迹。它不會留在任務的活動棧,是以使用者将不能夠傳回到它。在這種情況下, 

的onActivityResult()

如果你開始另一項活動,從這一活動的結果不會被調用。

這個屬性在API級别3引入的。

機器人:parentActivityName

活動的邏輯父的類名。該名稱必須在這裡提供給相應的類名比對

<活動>

元素的 

名稱:Android

屬性。

系統會讀取此屬性,以确定哪些活動,當使用者按下操作欄中向上按鈕應啟動。該系統還可以使用此資訊來合成與活動的背疊

TaskStackBuilder

為了支援API等級4 - 16,你也可以聲明與父活動

<元 ​​資料>

元素指定的值

“android.support.PARENT_ACTIVITY” 

。例如:
<activity 
    android:name = "com.example.app.ChildActivity" 
    android:label = "@string/title_child_activity" 
    android:parentActivityName = "com.example.myfirstapp.MainActivity"  > 
    <!--父活動的中繼資料來支援API級别4+ --> 
    <meta-data 
        android:name = "android.support.PARENT_ACTIVITY" 
        android:value = "com.example.app.MainActivity"  /> 
</activity>      

有關聲明父活動,以支援向上導航的更多資訊,請閱讀提供高達導航。

這個屬性在API級别16引入的。

機器人:許可

用戶端必須要推出的活動或以其他方式得到它的一個意圖做出回應權限的名稱。如果主叫方

startActivity()

或 

startActivityForResult()

 沒有被授予指定的權限,其意圖将不會傳遞到活動中。

如果沒有設定該屬性,通過設定權限 

<應用程式>

 元素的 

權限

 屬性适用于該活動。如果沒有屬性被設定時,活性不受權限保護。

有關權限的詳細資訊,請參閱 權限 在引進和其他文檔,部分 安全和權限。

機器人:過程

該活動應該運作的程序的名稱。通常情況下,一個應用程式的所有元件在應用程式中建立一個預設的程序名運作,你并不需要使用此屬性。但是,如果有必要,你可以用這個屬性覆寫預設的程序名,使您可以在多個流程傳播你的應用元件。

(“:”)如果配置設定給該屬性名稱以冒号開始,一個新的程序,私有的應用程式,在需要時建立和活動在這一過程中運作。如果程序名稱以小寫字母開頭,該活動将在名字的全局程序中運作,隻要它有權這樣做。這使得在不同應用程式的元件共享一個過程,減少資源的使用。

<應用程式>

元素的 

過程

 屬性可以為所有元件設定不同的預設程序名。

機器人:relinquishTaskIdentity

是否活動放棄其任務辨別符在任務堆棧它上面的活性。其根活動任務有這個屬性設定為“ 

 ”替換,在任務下一個活動的基地意向。如果接下來的活動也有這個屬性設定為“ 

 ”,那麼它會生成堿性意圖,它在相同的任務啟動任何活動。這繼續為每個活動,直到活動遇到有此屬性設定為“ 

 ”。預設值是“ 

 ”。

該屬性設定為“ 

 ”也允許活動的使用的 

ActivityManager.TaskDescription

改變标簽,顔色和圖示的總覽畫面。

機器人:screenOrientation

該活動的裝置上顯示的方向。

的值可以是以下的字元串中的任何一個:

“ 

未指定

 ”
的預設值。該系統選擇的方向。該政策時使用,是以,在具體情況下作出的選擇,可以從不同的裝置到裝置。
“ 

背後

 ”
相同的方向這立即将其下方在活動堆棧的活性。
“ 

景觀

 ”
橫向(顯示器寬度大于高)。
“ 

畫像

 ”
縱向(顯示器高度大于寬)。

reverseLandscape

在正常橫向相反的方向橫向的方向。 在API 9級。

reversePortrait

在正常縱向相反的方向縱向。 在API 9級。

sensorLandscape

橫向方向,但可以根據裝置傳感器是正常或反向的風景線。 在API 9級。
“ 

sensorPortrait

縱向方向,但可以是正常或反向根據裝置傳感器的畫像。 在API 9級。
“ 

userLandscape

 ”
橫向,但也可以是正常或反向景觀基于裝置傳感器和使用者的傳感器偏好。如果使用者已經鎖定基于傳感器的旋轉,這樣的行為一樣

的風景

,否則它的行為一樣

sensorLandscape

。 在API級别18添加。
“ 

userPortrait

 ”
縱向,但也可以是正常或基于裝置傳感器和使用者的傳感器偏好反轉的畫像。如果使用者已經鎖定基于傳感器的旋轉,這樣的行為一樣

的畫像

,否則它的行為一樣

sensorPortrait

。 在API級别18添加。
“ 

傳感器

 ”
的取向是由裝置取向傳感器确定。顯示器的取向取決于使用者是如何保持裝置; 當使用者旋轉裝置它的變化。某些裝置,不過,不會轉動到所有四個可能的方向,預設情況下。為了讓所有的四個方位,用

“fullSensor”

“ 

fullSensor

 ”
的方向由任何的4方向的裝置方位傳感器來确定。這類似于

“傳感器”

除了這允許任何4個可能的螢幕方向,無論什麼樣的裝置,通常會做(例如,某些裝置将無法正常使用反向縱向或橫向反轉,而這使那些)。增加在API 9級。
“ 

nosensor

 ”
取向不參照的實體方位傳感器來确定。該傳感器被忽略,是以顯示不會轉動的基礎上如何在使用者移動裝置。除了 ​​這一差別,系統選擇使用相同的政策作為“的方向

未指定

 ”設定。
“ 

使用者

 ”
使用者的目前優選的取向。
“ 

fullUser

 ”
如果使用者已經鎖定基于傳感器的旋轉,這樣的行為一樣

的使用者

,否則它的行為一樣

fullSensor

和允許任何4個可能的螢幕方向的。 在API級别18。
“ 

鎖定

 ”
鎖定方向,以目前的旋轉,無論是。 在API級别18。
注意:當你聲明的橫向或縱向的一個值,它被認為是該活動運作方向的硬性要求。是以,您聲明價值實作按服務過濾,如谷歌播放讓你的應用程式隻可用于支援你的活動所需的取向裝置。例如,如果你聲明或者

“風景”

“reverseLandscape” 

,或 

“sensorLandscape” 

,那麼你的應用程式将隻提供給支援橫向裝置。不過,你也應該明确地聲明,您的應用需要縱向或橫向與

<用途特征>

 元素。例如,

<使用特征的android:NAME =“android.hardware.screen.portrait”/>

。這純粹是由谷歌播放(和支援它的其他服務)及平台本身并不控制是否可以安裝你的應用程式時,系統僅支援某些方向提供了一個篩選行為。

機器人:stateNotNeeded

無論是否該活動可以被殺死,并成功地重新啟動,而不必儲存其狀态- “ 

 ”,如果它可以在不參考以前的狀态重新啟動,而“ 

,如果需要其以前的狀态。” 預設值是“ 

 ”。

通常情況下,前一個活動被暫時關閉,以節約資源,其 

的onSaveInstanceState()

 方法被調用。這種方法存儲在該活動的目前狀态 

對象,然後将其傳遞給 

的onCreate()

重新啟動活動時。如果這個屬性被設定為“ 

 ” 

的onSaveInstanceState()

可能不會調用和

的onCreate()

将被傳遞

而不是捆綁的-隻是因為它是當活動開始的第一次。

A“ 

 ”的設定確定了活動可在不存在保留狀态的重新啟動。例如,顯示在主螢幕的活動使用此設定以確定如果它崩潰出于某種原因,它不會删除。

機器人:taskAffinity

該活動具有用于具有親和性的任務。具有相同的親和力活動概念屬于相同的任務(從使用者的角度來看,同樣的“應用程式”)。任務的親和力是通過它的根活動的親和性來确定。

的親和力決定了兩件事情-該活性被重新父到任務(見

allowTaskReparenting

 屬性),并且當它與推出,将容納該活動的任務

FLAG_ACTIVITY_NEW_TASK

 标志。

預設情況下,在應用程式中的所有活動具有相同的親和力。您可以設定不同的此屬性将它們分組,甚至置于同一任務中不同的應用程式定義的活動。要指定活動沒有任何任務的親和力,将其設定為空字元串。

如果沒有設定該屬性,該活動将繼承親和力的應用程式設定(見 

<應用程式>

 元素的 

taskAffinity

屬性)。對于應用程式的預設親和力的名稱是由設定的包名 

<清單>

 元素。

安卓主題

引用到樣式定義資源對活動的總體主題。此自動設定活動的使用本主題上下文(見 

setTheme()

,并且還可以先于活動而被推出(以更好地比對什麼活動實際上看起來像)會導緻“起動”的動畫。

如果沒有設定該屬性,該活動将繼承應用程式作為一個整體的主題設定-從 

<應用程式>

 元素的 

主題

屬性。如果也沒有設定該屬性,則使用預設的系統主題。欲了解更多資訊,請參閱樣式和主題開 ​​發人員指南。

機器人:uiOptions

為活動的UI額外的選項。

必須是以下值之一。

描述

“沒有”

沒有額外的UI選項。這是預設的。

“splitActionBarWhenNarrow”

在螢幕顯示的操作項目的底部增加一個欄應用欄(也稱為 操作欄),受限于橫向空間時(例如,當在縱向模式在手機上)。相反,少數出現在螢幕頂部的應用程式欄行動項目,應用欄分成頂部導航部分和操作項的底部欄。這確定的空間合理量是由不僅可用于該操作的物品,也為在頂部導航和标題元素。菜單項目不跨越兩個酒吧分割; 他們總是一起出現。

有關應用欄的詳細資訊,請參閱添加應用欄教育訓練班。

在API級别14加入這個屬性。

機器人:windowSoftInputMode

該活動的主視窗如何用含有螢幕上的軟鍵盤視窗互動。這個屬性的設定會影響兩件事情:
  • 軟鍵盤的狀态 - 無論是隐藏或顯示 - 當活動成為使用者關注的焦點。
  • 調整該活動的主視窗中進行 - 無論是較小的調整,以騰出空間軟鍵盤,還是它的内容平移,使目前的焦點時可見視窗的部分被軟鍵盤覆寫。
該設定必須是下表中列出的值之一,或一“的組合

狀态...

 ”值加一“ 

調整......

 ”的價值。在任一組設定多個值-多“ 

的狀态......

 ”的價值觀,例如-已不确定的結果。(單個值由豎線

|

)。例如:
<活動 的android:windowSoftInputMode = “stateVisible | adjustResize” 。。。>      
值這裡設定(不是“ 

stateUnspecified

 ”和“ 

adjustUnspecified

在主題設定覆寫值”)。
描述
“ 

stateUnspecified

未指定的軟鍵盤的狀态(它是否隐藏或可見)。該系統将選擇一個合适的狀态或依賴于主題的設定。

這是軟鍵盤的行為的預設設定。

“ 

stateUnchanged

 ”
軟鍵盤保持在上次的,不管狀态是否可見或隐藏,當活動就浮出水面。
“ 

stateHidden

 ”
當使用者選擇該活動的軟鍵盤被隐藏 - 也就是說,當使用者肯定地導航着的活性,而不是背到它,因為離開另一個活動的。

stateAlwaysHidden

軟鍵盤總是隐藏在活動的主視窗有輸入焦點。
“ 

stateVisible

 ”
軟鍵盤時可見這是正常合适的(當使用者浏覽着該活動的主視窗)。

stateAlwaysVisible

也就是說,當使用者肯定地導航着的活性,而不是背到它,因為離開另一個活動的 - 當使用者選擇該活動的軟鍵盤變得可見。

adjustUnspecified

它是不确定的活動的主視窗是否調整大小以騰出空間給軟鍵盤,或平移視窗中的内容是否使目前焦點在螢幕上是可見的。該系統将自動選擇取決于視窗的内容是否具有可滾動的内容的任何布局的觀點,這些模式中的一種。如果有這樣的視圖,該視窗将被調整,在該滾動可以使更小的區域内的所有的視窗的内容可見的假設。

這是在主視窗的行為的預設設定。

“ 

adjustResize

 ”
活動的主視窗總是被調整,以騰出空間給軟鍵盤在螢幕上。
“ 

adjustPan

 ”
不能調整大小活動的主視窗,以騰出空間給軟鍵盤。相反,視窗中的内容會被自動平移,使目前的工作重點是永遠不會被鍵盤遮住,使用者可以随時檢視自己所鍵入的内容。這通常比調整大小不太理想的,因為使用者可能需要關閉軟鍵盤以獲得在與視窗的遮蔽部件互相作用。
這個屬性在API級别3引入的。
介紹了:
除了 ​​對所有API級别1屬性 

noHistory

和 

windowSoftInputMode

,這是在API級别3添加。
也可以看看:

<應用程式> 

<活動别名>

繼續閱讀