- 語法:
<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>
- 說明:
- 活動的別名,以
targetActivity
命名 屬性。目標必須與 並在資訊清單中的別名之前宣告其別名別名會將目標活動顯示為獨立實體,並且可擁有專屬的一組意圖 篩選器。而非 目標活動本身的意圖篩選器,找出哪些意圖 可以透過別名和系統如何啟動目標 就會處理別名
舉例來說,別名上的意圖篩選器 指定
"android.intent.action.MAIN"
和"android.intent.category.LAUNCHER"
」導致 會顯示在應用程式啟動器中,即使 篩選器,則會設定這些標記。targetActivity
是例外情況,<activity-alias>
屬性是<activity>
屬性的子集。對於該子集中的屬性,為目標設定的所有值都不會沿用到別名上。但是,對於不在該子集中的屬性,為目標活動設定的值也會套用至別名。 - 屬性:
android:enabled
- 指出系統能否透過使目標活動例項化
使用這個別名。
"true"
表示可以,"false"
表示不可以。 預設值為"true"
。<application>
元素有專屬的enabled
屬性,會套用至所有應用程式元件,包括活動別名。 「<application>
」和「<activity-alias>
」 屬性都必須為"true"
,系統才能例項化 並透過別名為目標活動如有任一屬性為"false"
,別名 無法運作。 android:exported
- 其他應用程式的元件能否啟動目標活動
透過這個別名。
"true"
表示可以,"false"
表示不可以。 如果是"false"
,則只有 元件,例如別名或具有相同使用者 ID 的應用程式。預設值取決於別名是否包含意圖篩選器。沒有任何篩選器時,只能指定別名的確切名稱,透過別名叫用活動。這表示 僅供應用程式內部使用,因為其他應用程式不知道該名稱。 因此,預設值為
"false"
。 另一方面,只要出現至少一個篩選器,即表示別名 適用於外部用途,因此預設值為"true"
。 android:icon
- 透過別名向使用者顯示時,目標活動的圖示。詳情請參閱
<activity>
元素的icon
屬性。 android:label
- 透過別名向使用者顯示時,別名的使用者可讀標籤。詳情請參閱
<activity>
元素的label
屬性。 android:name
- 別名的專屬名稱,名稱大致上 合格類別名稱但與目標活動的名稱不同 別名名稱可以任意指定不會參照實際類別。
android:permission
- 用戶端啟動目標活動所需的權限名稱
或透過別名執行某些操作如果呼叫者是
startActivity()
或startActivityForResult()
使用者未獲得指定權限,則不會啟用目標活動。該屬性會取代目標活動本身的任何權限設定。如果 未設定,也無需權限即可透過別名啟動目標。
如要進一步瞭解權限,請參閱 權限 部分。
android:targetActivity
- 可透過別名啟動的活動名稱。這個名稱必須與資訊清單中別名前方
<activity>
元素的name
屬性相符。
- 導入版本:
- API 級別 1
- 另請參閱:
<activity>
<活動別名>
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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)"]]