<activity>
<activity android:allowTaskReparenting=["true" | "false"] android:alwaysRetainTaskState=["true" | "false"] android:clearTaskOnLaunch=["true" | "false"] android:configChanges=["mcc", "mnc", "locale", "touchscreen", "keyboard", "keyboardHidden", "navigation", "screenLayout", "fontScale", "uiMode", "orientation", "screenSize", "smallestScreenSize"] 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:multiprocess=["true" | "false"] android:name="string" android:noHistory=["true" | "false"] android:parentActivityName="string" android:permission="string" android:process="string" 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>
<application>
<intent-filter>
<meta-data>
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.
android:allowTaskReparenting
true
" if it can move, and "
false
" if it must remain with the task where it started.
allowTaskReparenting
attribute of the
<application>
element applies to the activity. The default value is "
false
".
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
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.
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:clearTaskOnLaunch
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.
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.
true
", all of the activities on top of it (Q in this case) were removed when the user pressed
Home and the task went to the background. So the user sees only P when returning to the task.
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
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.
|
' — for example, "
locale|navigation|orientation
".
locale|navigation|orientation
"
"mcc " | The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC. 检测到MCC改变时调用——例如SIM卡被系统检测到后将更新MCC |
"mnc " | The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC. IMSI网络状态发送改变时调用——同上 |
"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.用户界面发生改变——这可能发生在用户把它的设备插入底座(dock)或者切换到了夜间模式。查看 API level8 计入的 UiModeManager . |
"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.
如果你的程序的最低API支持13或以上,你也可以通过设定screenSize值来检测改变,因为当系统发生横竖屏改变时,屏幕分辨率也会发生变化
|
"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). 当前屏幕的分辨率被改变时——这代表当横纵比发生改变时会触发这种状态,所以当用户切换横竖屏时也会触发这个值。当程序的api被设定在12或者以下时,activity会默认配置这个值(也就是说activity并不会重启,即使是运行在Android 3.2或者以上的设备中时) 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 thesmallestWidth 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). 当屏幕的物理尺寸改变时会触发这个值。它代表的是实际屏幕的改变,不包括当前屏幕的方向(横竖屏),所以这个属性只发生在物理屏幕被改变时,例如用户插入了一个外接屏幕。这个属性的改变实际相对应的是smallestWidth configuration.不过如果当程序的api被设定在12或者以下时,activity会默认配置这个值(也就是说activity并不会重启,即使是运行在Android 3.2或者以上的设备中时) 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. 当布局方向发生改变时,例如从LTR模式切换为RTL模式。 |
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.
onConfigurationChanged()
被调用时,一般情况下需要重新去配置所有资源(包括布局,drawable等等)。
android:enabled
true
" if it can be, and "
false
" if not. The default value is "
true
".
<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
true
" if the task should be
excluded from the list; set "
false
" if it should be
included. The default value is "
false
".
android:exported
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.
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
".
permission
attribute).
android:finishOnTaskLaunch
true
" if it should be shut down, and "
false
" if not. The default value is "
false
".
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
true
" if it should be enabled, and "
false
" if not. The default value is "
false
".
android:icon
android:label
attribute).
<application>
element's
icon
attribute).
<application>
element — is also the default icon for all the activity's intent filters (see the
<intent-filter>
element's
icon
attribute).
<intent-filter>
的icon属性)
android:label
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).
android:launchMode
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
".
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).
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.
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.
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.
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 itsonNewIntent() 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. |
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.
android:multiprocess
true
" if it can be, and "
false
" if not. The default value is "
false
".
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
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.
android:exported="false"
).
android:exported="false"
),参考
should not change this name
android:noHistory
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
".