`
zerozhiqin
  • 浏览: 965 次
  • 性别: Icon_minigender_1
  • 来自: 天津
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Activity属性详解(官方翻译)

阅读更多

 form : http://developer.android.com/guide/topics/manifest/activity-element.html

<activity>

SYNTAX:
<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>
 
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: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. 
决定当另一个和本activity具有相同affinity的activity启动时,本activity是否可以从当前task移动到新activity所在的task中——“true”代表可以从当前task移动到新打开的task,"false"表示此activity必须保持在当前task中不能变动。
 
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".
如果没有设置这个属性,那么他的值将会跟随application中笨属性的设置,如果application中也没有设置,那么默认值为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.
通常一个activity被启动时,这个activity会保持在打开它的task中,并再次完成其生命周期。你可以使用这个属性,在当前task不在显示时,把你的activity绑定到另一个具有相同affinity的task中。通常,这个属性被用来触发一个应用程序的activities移动到另一个应用的主任务中。
 
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.
例如一个e-mail应用中的一条信息包含了一个url链接用来转到一个网页,点击链接会打开一个activity来显示这个页面。显示页面的activity是由另外一个浏览器应用提供的,但这个浏览器的activity此时应该被当成e-mail应用的一个子activity。如果将浏览器提供的activity重新绑定(reparented)到email应用中,那么当用户退出网页时就能继续回到email中了。
 
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 thelaunchMode attribute.)
activity的affinity属性通过taskAffinity属性定义。一个task的affinity通过此task的根activity的affinity来决定。因此,通过定义affinity属性,根activity将始终存在于他们的task中。由于带有“singleTask”和“singInstance”属性的activities只能存在一个task的栈底,所以重新绑定(reparented)只对于启动模式为"standard"或"singleTop"的activity有效
 
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.
决定当前task中的activity是否始终被系统保持——“true”代表会,“false”代表允许系统将此task设定为最初的状态。默认值为false,这个属性仅对根activity有效,其他activity如果设定了这个属性也将被忽视。
 
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.
通常在一些情况下系统将清除一个task(清除根activity以上的所有activity),例如当用户从主页面中重现选择了这个task。或者用户长时间没有访问过这个task,例如30分钟后回到这个任务。
 
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.
不过如果把这个属性设定为true,用户将总能返回这个task的最后状态,不管他们是如何再次访问这个task的。这很常用,比如一个浏览器应用,用户不希望在再次访问后丢失它的状态(比如用户已经打开了许多标签等等)
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.
设置每当用户从主屏幕再次进入应用时,程序是否清除task中除根activity外的所有activitys——“true”代表始终清除其他的activity,反之为“false”。默认值为false。这个属性只对于根activity有意义,其他的activity如果设置了这个属性也将被忽略。
 
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.
如果这个属性被设置成了true,那么每次用户再次开启task时,都将显示根activity,无论用户之前做了什么操作,也无论他们是使用home键或使用back键退出的应用都会如此。如果这个属性被设置成了false,那当用户再次进入时也有可能会返回根activity(参考上面一个属性android:alwaysRetainTaskState中的说明),但不会总是返回根activity。
 
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 Home and the task went to the background. So the user sees only P when returning to the task.
假设,当从主屏幕运行了activity P,再从P中进入了activity Q。之后按下home键返回主屏幕,然后再点击程序打开activity P。正常情况下用户将会看到Q,因为P和Q在同一个task中,而且当前task顶为Q。但是如果我们给P设置这个属性为true。用户重复上面的这个操作将会看到P,此时Q将会被销毁。
 
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.
如果这个属性和allowTaskReparenting属性同时被设为true。那么带有affinity属性的activity将被重新绑定到其合适的stak中,而其他的activity将会被销毁。
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 itsonConfigurationChanged() method is called.
属性列举了当configuration改变时activity是否保存自己的状态。当应用允许时发生了configuration改变,默认情况下activity将关闭并重启自身,但是如果定义了这个属性,activity将不必重启,它将保持运行状态同时调用onConfigurationChanged()方法告知应用。
 

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.

请避免使用这个属性,把其当成最后的处理方式。请阅读Handling Runtime Changes来获得更多的信息,它描述了如何正确地处理由于configuration改变导致程序重启。
Any or all of the following strings are valid values for this attribute. Multiple values are separated by '|' — for example, "locale|navigation|orientation".
以下字段表示了这个属性的可用值,当程序使用多个值时可用使用“|”来分割。例如 "locale|navigation|orientation"
 
Value Description
"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 UiModeManagerAdded 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模式。
 
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.
所有的configuration改变将影响程序中的resource值。因此,当 onConfigurationChanged() 被调用时,一般情况下需要重新去配置所有资源(包括布局,drawable等等)。
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".
确定activity是否可以被程序初始化——“true”代表可以,“false”代表不行,默认值为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.
application节点也有的enabled属性,如果需要设定activity的enabled为true,那么application的enabled也必须被设定为true(他们默认都是true)。如果有一个不为true那么activity将不会被系统实例化
android:excludeFromRecents
Whether or not the task initiated by this activity should be excluded from the list of recently used applications ("recent apps"). 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".

 

设定当前activity是否可以从用户的最近应用列表(“recent app”)中看到。换句话说,如果activity是应用task的根activity,通过设定这个activity的这个属性,可以让你的程序在最近任务列表中不被显示(也就是说非根activity设定此属性无效)。“true”代表不被显示,“false”代表被显示。默认值为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.
设定程序是否可以被其他应用调用——“true”代表可以,“false”代表不行,如果被设定为了false,那么activity只能被其所在的应用调用,或者如果其他的应用和本应用使用相同的 user ID也可以调用此activity。
 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".
这个属性的默认值会根据activity是否包含 intent filters而不同。如果activity不包含任何的intent filters,这代表这个activity只能通过准确的包名和类名来打开。这以为着这个activity是当成应用内部activity来打开的(因为其他的程序并不知道你的包名和类名)。所有在这种情况下默认值为false。反之如果activity存在intent-filters,那么代表这个activity可以被外部调用,其默认值为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).
这个属性是定义其他app是否能调用打开此activity的唯一方式。你可以定义一个权限来限制哪个外部app可以调用这个activity(请参考permission属性)
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".
定义如果程序已经打开,当用户通过主屏幕再次点击app时本程序是否重新加载——“true”代表程序重新加载,反之为“false”,默认值为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.
如果这个属性和allowTaskReparenting属性同时设定为true,这个属性将覆盖allTaskReparenting,activity的affinity属性将被忽略。activity将不会被重新绑定,而是会被销毁。
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".
定义activity是否启用硬件加速——“true”代表打开硬件加速,反之为“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.
从Android3.0开始,可以对应用打开基于OpenGL的硬件加速,这可以提高许多2D绘制的性能。当硬件加速打开后,及时你没有明确地使用framework中的相关库,大部分Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera的运算也将会被加速。这能使得应用的动画,滑动更加平滑,应用整体反应速度也将得到提升。不过由于资源打开了硬件加速,你的应用将消耗更多的内存。
 
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.
注意不是所有的OpenGL 2D运算都会得到加速。如果你打开了硬件加速功能,请测试你的应用是否正确地运行了加速功能。
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).
定义代表activity的icon图标。例如程序启动activity的icon将会在应用列表中显示,icon属性通常伴随着label属性。

 

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).
这个图标必须被设定为一个drawable。如果没有设定,那么它将会跟随application中设定的icon属性。
 
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).
activity的图标——包括在activity设定的或者在application中设定的图标——也将被当成activity所有的intent filters的默认图标(参考 <intent-filter> 的icon属性)
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.
label属性应该是一个string的resource值。为了方便开发,他也可以被直接设定为一个普通字符串。
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:
这描述了activity将以何种运行方式启动。有4种模式结合activity中Intent的flags(FLAG_ACTIVITY_* 常量)来确定activity启动时将会发生何种状态

 

"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_TASKinstruction, in which case a different task is chosen — see the taskAffinity attribute).
正如下面的表格中显示的,这4种模式被分成了两类,“standard”和“singleTop”模式是一种,“singleTask”和“singleInstance”是另外一种。前一重模式的activity可以被实例化多次。他们的实力可以被加入任何一个activity运行栈(task)。正常情况下调用startActivity()方法能把他们加入当前的运行栈(除非Intent包含了FLAG_ACTIVITY_NEW_TASK指令,可以把这个activity加入另一个task——参照taskAffinity属性)
 
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.
相对的,带有“singleTask”和“singleInstance”值的activites只能在新的task中运行,他们将总是保持在task的栈底。此外,系统将只保存这个activity的唯一一个实例——当然也只保存唯一一个task
 
The "standard" and "singleTop" modes differ from each other in just one respect: Every time there's a new intent for a "standard" activity, a new instance of the class is created to respond to that intent. Each instance handles a single intent. Similarly, a new instance of a "singleTop" activity may also be created to handle a new intent. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created. In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.
"standard"和“singleTop”模式之间只有一点不同:每次当用新的Intent打开一个standard的activity,应用将会实例化一个新的activity类。每一个实例中都保存了一个独立的Intent,同样的,每一个singleTop模式的activity也能被创建并保存一个新的Intent。但是,如果一个task中已经有了一个singleTop的activity实例,并且这个实例目前位于栈顶,那么栈顶的实例将会接收到一个新的intent(在onNewIntent()方法中接收到);也就是说这个activity将不会被再次创建。在其他情况下——比如说,如果一个singleTop的activity已经被创建但是不在栈顶,或者他只是在当前栈的栈顶而不是目标栈的栈顶——此时将会创建一个新的activity实例并会将其加入栈中。(?)
 
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 ifFLAG_ACTIVITY_NEW_TASK was in the intent.
"singleTask"和"singleInstance"模式之间也有一点不同:"singleTask"模式将会总是存在于栈底,但是允许其他的activity运行到他所在的task中。"singleInstance"模式不允许自身栈内有其他的activity存在。如果在这个activity打开一个新的activity,那么新的activity将会被加到其他的task中——同intent中设置了FLAG_ACTIVITY_NEW_TASK的效果一样。
 
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 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.
 
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.
正如以上表格显示的一样,standard是activity的默认模式,适用于大部分的activities。singleTop模式也是一种常见而且实用的启动模式。但是另外两种模式对于大部分应用来说都不适用,因为他们和其他activity之间的相互关系对于用户来说会很陌生而且会使得其和大部分app有所区别。
 
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.
不管你选择什么用的启动模式,请确保测试当按下back键时从其他activity或者从其他task返回activity的可用性
 
For more information on launch modes and their interaction with Intent flags, see the Tasks and Back Stack document.
更多关于启动模式相互关系的内容,请参考 Tasks and Back Stack
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".
定义activity是否可以被运行到那个启动它的进程中——true代表可以,falser代表不能,默认值为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.
正常情况下,一个新的activity实例会被运行在application中定义的进程中,所以所有的activity实例都会被运行在同一个进程里。但是如果这个属性被设置为true,那么activity的实例则可以再多进程中运行,不论在哪运行都允许系统创建他们(只要权限允许),这是几乎从来不必要或者定义的东西。
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.
定义activity的类名,其必须是Activity的子类。
 
Once you publish your application, you should not change this name (unless you've setandroid:exported="false").
只要你发布了你的app,你就不能改变这个值(除非你设定了tandroid:exported="false"),参考 should not change this name
 
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".
设定当用户从当前activity进入其他activity后,当前activity是否被被结束(会调用其的finish()方法)。“true”代表它将会被关闭,“false”代表其不会被关闭,默认值为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.
当值被设定为true时,activity将会被从task中移除,所以用户将无法回到这个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.
定义当前activity的父activity。这个属性必须与父activity的name属性相同。
 
The system reads this attribute to determine which activity should be started when the use presses the Up button in the action bar. The system can also use this information to synthesize a back stack of activities with TaskStackBuilder.
系统通过读取这个属性来确定当用户点击actionbar的Up按钮后应该打开哪个activity。系统同事可以使用这个信息通过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:
在API4~16上,如果你想使用这个属性,你可以通过<meta-data>节点来定义它,如下所示:
 
<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.
定义外部程序打开此activity或回应此activity必须包含的permission。如果调用startactivity()或者startActivityForResult()的activity没有加入相应的permission,那么这个intent将不会被传达到目标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.
如果activity中这个权限没有被设置,那么它将会遵从application中的permission设置。如果都没有设置的话那么程序将不会得到保护。
 
For more information on permissions, see the Permissions section in the introduction and another document, Security and Permissions.
更多关于权限的内容,请参考 Permissions 或者 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.
设定这个属性将决定activity会被运行在哪个进程(process)中。正常情况下,app中所有的组件都运行在默认的进程里,你不需要设定这个属性。但是如果必要的话,你可以重写默认的进程名,他允许你的app组件运行在多进程中。
 
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.
如果这个属性设定的进程名以“:”开头,那么新打开的进程将作为app的私有进程。否则如果具有相关权限的话,activity将变成一个全局的进程。它允许不同的app共享这个进程,减少资源的开销。
 
The <application> element's process attribute can set a different default process name for all components.
application标签中的process属性可以自定义,来声明全局的进程名
android:screenOrientation
The orientation of the activity's display on the device.
定义activity的屏幕方向

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.
和栈内下方的activity使用相同的策略
"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 sensorLandscapeAdded 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 sensorPortraitAdded 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".
根据用户设备旋转来选择显示方向,有的设备并不完全支持4个方向的旋转,如果想支持可以使用 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 asuser, 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".
定义是否activity可以在重启时保存之前的状态——“true”代表重启时不读取之前的状态,“false”代表以之前的状态重启,默认值为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.
正常情况下在activity暂时被关闭时保存资源,此时onSaveInstanceState()方法会被调用。这个方法把activity当前的状态保存在Bundle中,当程序再次运行时,onCreate()方法将被调用,并且之前保存的参数会传入onCreate()方法中。但是如果这个属性被设定为true,那么onSaveInstanceState()方法可能就不会被调用,同时onCreate()方法将会被传入一个空的Bundle——和重新打开一个新的activity一样。
 
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.
设定为“true”将保证activity可以再重启的时候不保留之前状态,例如显示主界面的activity使用了这个属性来保证它不会因为一些原因被删除,例如发生程序崩溃等。
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.
定义activity的task关系。带有相同taskAffinity的activies理论上将会被放到同一个task中。task的affinity属性由其栈底的activity决定。
 
The affinity determines two things — the task that the activity is re-parented to (see theallowTaskReparenting attribute) and the task that will house the activity when it is launched with theFLAG_ACTIVITY_NEW_TASK flag.
affinity 属性定义了两件事——1activity将可以被重新绑定到与其相同的task中(参考allowTaskReparenting属性);2如果一个activity在启动时带上FLAG_ACTIVITY_NEW_TASK参数,那么这个activity将会被重新绑定到别的栈中。
 
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.
默认状态下,app中所有的activities都有意义的affinity属性,你可以设置这个属性来对他们进行分组,也可以把不同应用程序中的activity放到同一个task中。如果想指定此activity不加入任何task,可以把它设置为一个空字符串。
 
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.
如果这个属性没有被设定,那么activity将会继承application中的设定。默认的affinity名为app的包名。
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 ActionBar, 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 action bar at the top of the screen, the action 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 action bar, see the Action Bar developer guide.

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:
这个属性配置了activity和软键盘之间的相互作用,这个属性影响有以下两点:
  • The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention. 当activity被显示给用户后软键盘的状态——无论其是之前否显示
  • 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. activity调整主窗口的方式——是否缩小自身重新布局来腾出空间给软键盘,或者当软键盘覆盖在activity上时移动activity,将当前输入焦点显示给用户。
 
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:
这个属性必须是以下表格中的一个值,或者也可以用一个"state...."值加上一个"adjust..."值来组成。如果你使用了多个同组的值——比如多个"state...."来组成一个值——那么其结果将会不可预期。两个值之间使用“|”分割。如下:
 
<activityandroid: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.
软键盘的显示状态不特殊指定。系统将选择适当的状态或者从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.
软键盘将保持之前的状态,打开activity时无论之前是打开或者关闭状态,软键盘都将保持这个状态。
"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.
当用户选择activity时,隐藏软键盘——就是说,当用户进入一个activity会触发隐藏,但是如果用户返回到activity将不会触发。
"stateAlwaysHidden" The soft keyboard is always hidden when the activity's main window has input focus.
当activity的主窗口有输入焦点时,软键盘将总会被隐藏。
"stateVisible" The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window).
软键盘将在适当的时候显示(比如当用户导航到activity的主窗口后)
"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.
当用户选择activity时软件盘将一定被显示——也就是用户选择进入此activity时软键盘会被显示,而当用户退出其他activity返回此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.
该Activity主窗口总是自动调整屏幕的大小以便留出软键盘的空间。
"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.
 该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。相对于resize这个值可能会比较不令用户满意,因为用户可能需要关闭软键盘才能与被覆盖的内容进行交互操作。

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:
分享到:
评论

相关推荐

    Android项目基本结构详解

    【Android项目基本结构详解】 Android项目的基本结构是开发者进行Android应用开发的基础,尤其对于初学者而言,理解这一结构至关重要。本文将从最基础的内容出发,介绍如何使用C#进行Android应用开发。 首先,...

    Android学习指南中文版(安卓中文翻译)

    - **Affinity**: 用于控制Activity加入哪个任务的属性。 - **加载模式(Launch Mode)**: 控制Activity如何加载到back stack中的方式。 - **清理堆栈**: 控制Activity从back stack中移除的方式。 **1.8 进程和线程** ...

    android 开发指南中文版

    - **Affinity(吸引力)和新任务**:探讨了如何控制Activity启动时加入的任务栈,以及Affinity属性的作用。 - **加载模式**:解释了启动Activity的不同模式及其对任务栈的影响。 - **清理堆栈**:介绍了解除Activity...

    Android NDK翻译之 NDK-GDB.html

    《Android NDK调试指南——NDK-GDB详解》 Android NDK-GDB是针对使用C/C++编程语言在Android平台上开发应用的开发者所必备的调试工具。从NDK r4版本开始,NDK引入了NDK-GDB,使得开发者能够方便地对本地代码进行...

    android API

    无论个人还是团队,只要翻译了Android官方相关文章,都可以与翻译组共享进度。翻译组也欢迎收到邮件分享,并避免重复翻译。未来,计划推出类似chm界面风格但支持自动更新内容的客户端程序。 #### 八、开发者指南...

    Android中文API.rar

    这些教程通常由官方文档和社区翻译组成,如Android官方API文档完整版.chm,提供了官方原版的API参考,而Android中文翻译组的教程则更便于中文使用者理解和学习。 五、AndroidBox0.5 AndroidBox可能是一个开发工具...

    BPMN2.0标准规范英文

    ### BPMN 2.0标准规范详解 #### 一、概述 《Business Process Model and Notation (BPMN) Version 2.0》是Object Management Group(OMG)发布的一个重要标准文档,它定义了一套用于图形化表示业务流程的标准符号和...

    kotlin中文教程高清PDF(带书签)

    - **可见性修饰符**:详解Kotlin中的访问控制符,如public、private等。 - **修饰符**:进一步探讨其他修饰符,例如final、open等的作用。 - **构造器**:深入分析主构造器与次构造器的区别和用法。 - **润色我们的...

    android完全中文API

    《Android完全中文API详解》 在移动开发领域,Android占据着重要的地位,其丰富的功能和开源特性吸引了众多开发者。然而,对于那些英语不是母语的开发者来说,阅读英文API文档可能会遇到困难。为此,"android完全...

    xposed_demo

    【Xposed框架详解】 Xposed框架是一款在Android系统上运行的强大的插件系统,它允许开发者通过编写模块来改变系统的内部行为,而无需修改系统核心文件。"xposed_demo"这个项目显然旨在演示如何利用Xposed框架进行...

    UML1.0标准中英文对照

    **UML 1.0 知识点详解** UML(Unified Modeling Language)1.0是一种通用的建模语言,用于软件开发中的可视化建模。它由对象管理组(OMG)于1997年发布,是软件工程领域的重要里程碑,为软件设计师和开发者提供了一...

    AndroidAPI

    ### Android API核心知识点详解 #### 一、概述 Android API(应用程序编程接口)是指一系列预定义的函数,这些函数能够帮助开发者访问操作系统内的各种服务和功能。对于Android开发者而言,熟练掌握API是至关重要...

    [精通Android.3].(Satya.Komatineni).扫描版.pdf

    《精通Android.3》这本书由Satya Komatineni撰写,杨越翻译,是一部深度解析Android开发的专业著作。书中详尽地介绍了Android平台的各种核心概念、技术以及开发实践,旨在帮助开发者提升在Android领域的专业技能。 ...

    Android写一个实时输入框功能

    Android 实时输入框功能实现详解 Android 实时输入框是一个非常实用的功能,它可以实时监听用户的输入,并将其显示在界面上。本文将详细介绍如何使用 Android 实现实时输入框功能,并提供了详细的示例代码。 知识...

    一步一步的使用C++和OPENGL实现COLLADA骨骼动画

    ### 使用C++与OpenGL实现COLLADA骨骼动画详解 #### 一、引言 随着计算机图形学的发展,3D模型的复杂性和表现力不断提高。骨骼动画作为一种常见的技术,被广泛应用于游戏开发、电影制作等领域。COLLADA...

Global site tag (gtag.js) - Google Analytics