- 语法:
<activity-alias android:enabled=["true" | "false"] android:exported=["true" | "false"] android:icon="drawable resource" android:label="string resource" android:name="string" android:permission="string" android:targetActivity="string" > ... </activity-alias>
- 包含于:
<application>
- 可包含:
<intent-filter>
<meta-data>
- 说明:
- activity 的别名,由
targetActivity
属性命名。目标必须与别名位于同一应用中,并在清单中的别名之前进行声明。别名将目标 activity 呈现为独立的实体,并且可以具有自己的一组 intent 过滤器。这些 intent 过滤器(而不是目标 activity 本身的 intent 过滤器)决定了哪些 intent 可以通过别名激活目标,以及系统如何处理别名。
例如,即使目标 activity 本身所有的过滤器都未设置
"android.intent.action.MAIN"
和"android.intent.category.LAUNCHER"
标志,别名的 intent 过滤器也可以指定这些标志,使其呈现在应用启动器中。除了
targetActivity
之外,<activity-alias>
属性是<activity>
属性的子集。对于子集中的属性,为目标设置的任何值都不会沿用于别名。不过,对于不在子集中的属性,为目标 activity 设置的值也会应用于别名。 - 属性:
android:enabled
- 确定系统是否可以通过此别名实例化目标 activity。如果可以,则设为
"true"
,否则设为"false"
。默认值为"true"
。<application>
元素具有自己的enabled
属性,该属性适用于所有应用组件,包括 activity 别名。<application>
和<activity-alias>
属性必须都设为"true"
,系统才能通过别名实例化目标 activity。如果其中任一属性设为"false"
,则别名不起作用。 android:exported
- 确定其他应用的组件是否可以通过此别名启动目标 activity。如果可以,则设为
"true"
,否则设为"false"
。 如果设为"false"
,则只有与别名在同一应用中的组件或具有同一用户 ID 的应用的组件可以通过别名启动目标 activity。默认值取决于别名是否包含 intent 过滤器。没有任何过滤器时,只有指定别名的确切名称,才能通过别名调用 activity。这意味着别名仅供应用内部使用,因为其他应用不知道其名称。因此,默认值为
"false"
。另一方面,如果存在至少一个过滤器,则意味着该别名会供外部使用,所以默认值为"true"
。 android:icon
- 通过别名呈现给用户时,目标 activity 的图标。如需了解详情,请参考
<activity>
元素的icon
属性。 android:label
- 通过别名呈现给用户时,别名的用户可读标签。如需了解详情,请参考
<activity>
元素的label
属性。 android:name
- 别名的唯一名称。该名称类似于完全限定的类名称。但是,与目标 activity 的名称不同,别名名称是任意的,它不引用实际类。
android:permission
- 客户端要使用别名启动目标 activity 或让其执行某项操作而必须具备的权限的名称。如果没有向
startActivity()
或startActivityForResult()
的调用方授予指定的权限,目标 activity 不会激活。此属性会取代为目标 activity 本身设置的任何权限。如果未设置此属性,则无需权限即可通过别名激活目标。
如需详细了解权限,请参阅应用清单概览中的权限部分。
android:targetActivity
- 可通过别名激活的 activity 的名称。此名称必须与清单中别名前面的
<activity>
元素的name
属性匹配。
- 引入于:
- API 级别 1
- 另请参阅:
<activity>
<activity-别名>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <activity-alias\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cactivity-alias android:enabled=[\"true\" | \"false\"]\n android:exported=[\"true\" | \"false\"]\n android:icon=\"drawable resource\"\n android:label=\"string resource\"\n android:name=\"string\"\n android:permission=\"string\"\n android:targetActivity=\"string\" \u003e\n ...\n \u003c/activity-alias\u003e\n ```\n\ncontained in:\n: [\u003capplication\u003e](/guide/topics/manifest/application-element)\n\ncan contain:\n: [\u003cintent-filter\u003e](/guide/topics/manifest/intent-filter-element)\n\n [\u003cmeta-data\u003e](/guide/topics/manifest/meta-data-element)\n\ndescription:\n: An alias for an activity, named by the `targetActivity`\n attribute. The target must be in the same application as the\n alias and declared before the alias in the manifest.\n\n\n The alias presents the target activity as an independent entity, and can have its own set of intent\n filters. They, rather than the\n intent filters on the target activity itself, determine which intents\n can activate the target through the alias and how the system\n treats the alias.\n\n For example, the intent filters on the alias might\n specify the [\"android.intent.action.MAIN\"](/reference/android/content/Intent#ACTION_MAIN)\n and [\"android.intent.category.LAUNCHER\"](/reference/android/content/Intent#CATEGORY_LAUNCHER)\" flags, causing it to\n be represented in the application launcher, even though none of the\n filters on the target activity itself set these flags.\n\n\n With the exception of `targetActivity`, `\u003cactivity-alias\u003e`\n attributes are a subset of [\u003cactivity\u003e](/guide/topics/manifest/activity-element) attributes.\n For attributes in the subset, none of the values set for the target carry over\n to the alias. However, for attributes not in the subset, the values set for\n the target activity also apply to the alias.\n\nattributes:\n:\n\n `android:enabled`\n : Whether the target activity can be instantiated by the system through\n this alias. `\"true\"` if it can be, and `\"false\"` if not.\n The default value is `\"true\"`.\n\n\n The [\u003capplication\u003e](/guide/topics/manifest/application-element) element has its own\n [enabled](/guide/topics/manifest/application-element#enabled) attribute that applies to all\n application components, including activity aliases. The\n `\u003capplication\u003e` and `\u003cactivity-alias\u003e`\n attributes must both be `\"true\"` for the system to be able to instantiate\n the target activity through the alias. If either is `\"false\"`, the alias\n doesn't work.\n\n `android:exported`\n : Whether the components of other applications can launch the target activity\n through this alias. `\"true\"` if they can, and `\"false\"` if not.\n If `\"false\"`, the target activity can be launched through the alias only by\n components of the same application as the alias or applications with the same user ID.\n\n\n The default value depends on whether the alias contains intent filters. The\n absence of any filters means that the activity can be invoked through the alias\n only by specifying the exact name of the alias. This implies that the alias\n is intended only for application-internal use, since others don't know its name.\n So, the default value is `\"false\"`.\n On the other hand, the presence of at least one filter implies that the alias\n is intended for external use, so the default value is `\"true\"`.\n\n `android:icon`\n : An icon for the target activity when presented to users through the alias.\n For more information, see the [\u003cactivity\u003e](/guide/topics/manifest/activity-element) element's\n [icon](/guide/topics/manifest/activity-element#icon) attribute.\n\n `android:label`\n : A user-readable label for the alias when presented to users through the alias.\n For more information, see the [\u003cactivity\u003e](/guide/topics/manifest/activity-element) element's\n [label](/guide/topics/manifest/activity-element#label) attribute.\n\n \u003cbr /\u003e\n\n `android:name`\n\n : A unique name for the alias. The name resembles a fully qualified class name. But, unlike the name of the target activity, the alias name is arbitrary. It doesn't refer to an actual class. \u003cbr /\u003e\n\n `android:permission`\n : The name of a permission that clients must have to launch the target activity\n or get it to do something using the alias. If a caller of\n [startActivity()](/reference/android/content/Context#startActivity(android.content.Intent)) or\n [startActivityForResult()](/reference/android/app/Activity#startActivityForResult(android.content.Intent, int))\n isn't granted the specified permission, the target activity isn't activated.\n\n This attribute supplants any permission set for the target activity itself. If\n it isn't set, a permission isn't needed to activate the target through the alias.\n\n\n For more information about permissions, see the\n [Permissions](/guide/topics/manifest/manifest-intro#perms)\n section in the app manifest overview.\n\n `android:targetActivity`\n : The name of the activity that can be activated through the alias.\n This name must match the `name` attribute of an\n [\u003cactivity\u003e](/guide/topics/manifest/activity-element) element that precedes\n the alias in the manifest.\n\n \u003cbr /\u003e\n\nintroduced in:\n: API level 1\n\nsee also:\n: [\u003cactivity\u003e](/guide/topics/manifest/activity-element)"]]