AndroidManifest.xml文件中<activity>元素用法
- AndroidManifest.xml文件中
元素用法
- 语法
- 用法描述
- 属性
- android:allowEmbedded
- android:allowTaskReparenting
- android:alwaysRetainTaskState
- android:autoRemoveFromRecents
- android:banner
- android:clearTaskOnLaunch
- android:colorMode
- android:configChanges
- android:directBootAware
- android:documentLaunchMode
- android:enabled
- android:excludeFromRecents
- android:exported
- android:finishOnTaskLaunch
- android:hardwareAccelerated
- android:icon
- android:immersive
- android:label
- android:launchMode
- android:maxRecents
- android:maxAspectRatio
- android:multiprocess
- android:name
- android:noHistory
- android:parentActivityName
- android:persistableMode
- android:permission
- android:process
- android:relinquishTaskIdentity
- android:screenOrientation
- android:showForAllUsers
- android:stateNotNeeded
- android:taskAffinity
- android:theme
- android:uiOptions
- android:windowSoftInputMode
语法
<activity android:allowEmbedded=["true" | "false"]
android:allowTaskReparenting=["true" | "false"]
android:alwaysRetainTaskState=["true" | "false"]
android:autoRemoveFromRecents=["true" | "false"]
android:banner="drawable resource"
android:clearTaskOnLaunch=["true" | "false"]
android:colorMode=[ "hdr" | "wideColorGamut"]
android:configChanges=["mcc", "mnc", "locale",
"touchscreen", "keyboard", "keyboardHidden",
"navigation", "screenLayout", "fontScale",
"uiMode", "orientation", "density",
"screenSize", "smallestScreenSize"]
android:directBootAware=["true" | "false"]
android:documentLaunchMode=["intoExisting" | "always" |
"none" | "never"]
android:enabled=["true" | "false"]
android:excludeFromRecents=["true" | "false"]
android:exported=["true" | "false"]
android:finishOnTaskLaunch=["true" | "false"]
android:hardwareAccelerated=["true" | "false"]
android:icon="drawable resource"
android:immersive=["true" | "false"]
android:label="string resource"
android:launchMode=["standard" | "singleTop" |
"singleTask" | "singleInstance"]
android:maxRecents="integer"
android:maxAspectRatio="float"
android:multiprocess=["true" | "false"]
android:name="string"
android:noHistory=["true" | "false"]
android:parentActivityName="string"
android:persistableMode=["persistRootOnly" |
"persistAcrossReboots" | "persistNever"]
android:permission="string"
android:process="string"
android:relinquishTaskIdentity=["true" | "false"]
android:resizeableActivity=["true" | "false"]
android:screenOrientation=["unspecified" | "behind" |
"landscape" | "portrait" |
"reverseLandscape" | "reversePortrait" |
"sensorLandscape" | "sensorPortrait" |
"userLandscape" | "userPortrait" |
"sensor" | "fullSensor" | "nosensor" |
"user" | "fullUser" | "locked"]
android:showForAllUsers=["true" | "false"]
android:stateNotNeeded=["true" | "false"]
android:supportsPictureInPicture=["true" | "false"]
android:taskAffinity="string"
android:theme="resource or theme"
android:uiOptions=["none" | "splitActionBarWhenNarrow"]
android:windowSoftInputMode=["stateUnspecified",
"stateUnchanged", "stateHidden",
"stateAlwaysHidden", "stateVisible",
"stateAlwaysVisible", "adjustUnspecified",
"adjustResize", "adjustPan"] >
. . .
</activity>
<activity>
必须包含在<application>
元素中<activity>
可以包含<intent-filter>
<meta-data>
<layout>
用法描述
声明一个activity(Activity
的子类),实现应程序的虚拟用户接口。所有的activity都在manifest文件中用<activity>
元素表示任何未在清单文件声明activity都无法运行,以至于应用程序崩溃。
属性
android:allowEmbedded
表示该activity可以作为另一个activity嵌入子项启动。特别是在子activity放在另一个activity容器中的情况下。例如在穿戴应用中用作自定义通知的activity就必须声明该属性,因而可以在驻留在另一个进程的上下文流中显示activity。
该属性默认值为false
android:allowTaskReparenting
无论该activity是否可以从启动它的任务栈移动到下一个在前台与其有相关性的任务栈。如果设置为“true”则可以移动,false则不可以移动并存放在启动的任务栈中。
如果activity没有设置该属性,则直接取
<application>
元素中对应的属性值。allowTaskReparenting
默认值为”false
“.
正常情况下,当一个activity启动,它便与启动它的activity的任务栈相关联,并且整个生命周期都会停留在该任务栈当中。你可以使用此属性强制将activity分配到有相同affinity的任务栈当中。通常,它用于使应用程序的activity移动到与该应用程序关联的主任务。
比如,一封邮件消息里面包含了一个网址,点击该连接拉起了一个activity显示网页。该activity由浏览器应用定义,但是由邮件的任务栈里面启动。如果重设到浏览器任务栈,当点击浏览器应用的时候将会显示该activity。邮件任务栈再次切换到前面的话,该activity将不会显示。
activity的亲和力由taskAffinity
熟悉定义。一个任务栈的亲和力是由读取的根activity的亲和力决定的。因此,根据定义,根activity总是在同一亲缘关系的任务栈中。由于使用”singleTask
“或者是”singleInstance
“的启动模式的activity只能位于任务栈的根目录,因此重新设置任务栈只能使用”standard
“和”singleTop
“的启动模式。
android:alwaysRetainTaskState
activity所在的任务栈的状态是否始终由系统维护,如果是,则为“true
”,如果为”false
“,则表示允许系统在某些情况下将任务重置为其初始状态。默认值为“false
”。该属性仅仅对根activity有效,对其他activity完全无效。
通常,当用户从主屏幕重新选择该任务时,系统会在某些情况下清除任务栈(清除在根activity之上的所有activity)。通常情况下,如果用户在一段时间内(比如30分钟)未访问该任务栈,则会执行上述操作。
然而,当此属性为“true
”时,用户将总是返回到上一个状态的任务。比如,在诸如Web浏览器之类的应用程序中,这是有用的,其中存在许多用户不想丢失的状态(例如多个打开的选项卡)。
android:autoRemoveFromRecents
启动携带有该属性的activity,activity所在的任务是否保留在预览屏幕中,直到任务中的最后一个activity执行完成为止。如果为”true
“,该任务将会自动从预览屏幕中移除。这将覆盖调用者使用的FLAG_ACTIVITY_RETAIN_IN_RECENTS
值。并且它必须是布尔值。
android:banner
android:clearTaskOnLaunch
android:colorMode
android:configChanges
android:directBootAware
android:documentLaunchMode
android:enabled
android:excludeFromRecents
android:exported
android:finishOnTaskLaunch
android:hardwareAccelerated
android:icon
android:immersive
android:label
android:launchMode
android:maxRecents
android:maxAspectRatio
android:multiprocess
android:name
android:noHistory
android:parentActivityName
android:persistableMode
android:permission
android:process
android:relinquishTaskIdentity
android:screenOrientation
android:showForAllUsers
android:stateNotNeeded
android:taskAffinity
android:theme
android:uiOptions
android:windowSoftInputMode
原文地址 https://blog.csdn.net/u013560890/article/details/81277233