自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
活動啟動政策
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
活動啟動行為是由應用程式 AndroidManifest.xml
檔案中的啟動模式、意圖旗標和呼叫端提供的 ActivityOptions 定義。使用 ActivityOption#setLaunchDisplayId(int)
指定活動啟動時的特定顯示裝置。
- 根據預設,活動會在與呼叫端相同的螢幕上啟動。舉例來說,從啟動器啟動的活動新例項應放置在同一個畫面上,且不含額外的旗標或選項。請務必使用正確的啟動內容 (活動與應用程式)。
- 如果啟動作業是從與特定顯示畫面無關的來源執行 (例如從殼層或應用程式情境執行),則活動會放置在使用者上次與裝置互動或上次啟動活動的頂端顯示畫面。
- 啟動活動的意圖可解析為系統中現有的活動例項。在這種情況下,如果未提供其他標記,活動會顯示在上次使用活動的相同螢幕上。如果使用
ActivityOptions#setTargetDisplayId()
指定目標顯示裝置,系統會將活動移至該裝置 (如果安全性和其他限制允許的話)。
安全性限制
為避免惡意應用程式從其建立的虛擬顯示器表面讀取使用者敏感資訊,進而濫用這些資訊,應用程式只能在 Android 10 中的虛擬顯示器上啟動自身的活動。不過,請注意以下幾點:
- 具有
INTERNAL_SYSTEM_WINDOW
權限的系統元件可在任何螢幕上啟動。
- 具有
ACTIVITY_EMBEDDING
權限的呼叫端可以從具有標記 ActivityInfo.FLAG_ALLOW_EMBEDDED
的其他應用程式啟動活動。
- 只有螢幕的擁有者或螢幕上顯示的活動,才能在私人螢幕上啟動活動。
在螢幕上新增視窗時,也適用類似的限制。
Android 10 包含 ActivityManager#isActivityStartAllowedOnDisplay(Context context, int
displayId, Intent intent)
方法,可在嘗試在螢幕上啟動應用程式前,先檢查應用程式的安全性限制。在 Android 9 (和以下版本) 中,限制啟動結果會擲回 SecurityException
。
大部分的安全限制都會套用在 ActivityStackSupervisor#isCallerAllowedToLaunchOnDisplay()
方法中。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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 launch policy\n\n*Activity launch behavior* is defined by launch modes in the\n`AndroidManifest.xml` files of apps, intent flags, and ActivityOptions\nprovided by the caller. Use `ActivityOption#setLaunchDisplayId(int)` to\ntarget a specific display for activity launch.\n\n- By default, the activity launches on the same display as the caller. For example, a new instance of an activity started from the launcher should be placed on the same display without additional flags or options. Be sure to use the correct context (Activity versus Application) for launch.\n- If the launch is performed from a source not associated with a specific display (such as from a shell or Application context), then the activity is placed on the top display on which the user last interacted with the device or from which the last activity was launched.\n- Intent to launch an activity can be resolved to an existing activity instance in the system. In such a case, if no additional flags were provided, an activity surfaces on the same display where it was last used. If the target display is specified with `ActivityOptions#setTargetDisplayId()`, then the activity is moved to that display (if allowed by security and other restrictions).\n\nSecurity restrictions\n---------------------\n\nTo prevent a malicious app from misappropriating user-sensitive information\nby reading it from the surface of a virtual display that it has created, apps can\nlaunch their own activities *only* on a virtual display of their creation\nin Android 10. However:\n\n- System components with the `INTERNAL_SYSTEM_WINDOW` permission can launch on any display.\n- Callers with the `ACTIVITY_EMBEDDING` permission can launch activities from other apps that have the flag `ActivityInfo.FLAG_ALLOW_EMBEDDED`.\n- Activity launches on private displays are allowed only for the owner or activities present on that display.\n\nSimilar restrictions apply to adding windows to displays.\n\nAndroid 10 includes the\n`ActivityManager#isActivityStartAllowedOnDisplay(Context context, int\ndisplayId, Intent intent)` method to check security restrictions for the\napp before attempting to launch on a display. In Android 9\n(and lower), restricted launch results throw `SecurityException`.\n\nMost security restrictions are applied in the\n`ActivityStackSupervisor#isCallerAllowedToLaunchOnDisplay()` method."]]