自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
工作管理員
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在 Android 13 中,我們推出了名為「Task Manager」的新系統 UI 操作元素,可通知使用者背景應用程式前景服務使用的狀態和資源,並讓使用者停止這些應用程式。
在 Android 13 中推出通知權限後,使用者可以控制關閉來自背景應用程式的通知,這些應用程式會執行前景服務,用於位置、媒體播放和投影、資料同步、視訊和語音通話,以及已連結的裝置。關閉這類通知後,系統就不會向使用者顯示前景服務的必要通知,無法顯示其狀態和資源使用情形。工作管理員會在「快速設定」畫面上新增資訊列,讓使用者瞭解在背景執行的應用程式,以及這些應用程式使用了哪些手機資源 (例如記憶體和電池)。透過這個介面,使用者會收到通知,指出應用程式是否長時間執行前景服務,並可選擇停止應用程式。可用性元素會以不明顯的方式顯示在螢幕上,以免遮蓋重要通知。詳情請參閱工作管理員。
為背景應用程式實作工作管理員
雖然這項功能有參考的 AOSP 實作項目,但 Android 裝置實作人員可以自訂及修改這個系統 UI。對於裝置核心功能的應用程式 (例如撥號和相機),請勿在工作管理員中顯示停止操作元素。
AOSP 實作項目會在 System UI 和 System Server 之間使用新的內部回呼 API。這個 API 可讓系統伺服器在啟動新的前景服務時通知系統 UI。使用者要求時,API 也會通知系統伺服器停止特定應用程式。
驗證 Task Manager 的背景應用程式通知
如要進行手動測試,請針對在背景執行的應用程式驗證工作管理員功能。
如要進行單元測試,請使用 AOSP 提供的單元測試。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Task Manager\n\nIn Android 13, a new System UI affordance called the\n[Task Manager](https://developer.android.com/about/versions/13/changes/fgs-manager)\nnotifies the user about the state and resources being used by the foreground\nservices on background apps and enables the user to stop these apps.\n\nWith the introduction of [notification permissions](https://developer.android.com/about/versions/13/changes/notification-permission)\nin Android 13, users have control over turning off\nnotifications from background apps that run [foreground services](https://developer.android.com/guide/components/foreground-services)\nfor location, media playback and projection, data sync, video and voice calls,\nand connected devices. When such notifications are turned off, required\nnotifications from foreground services that indicate their state and resource\nusage to the user aren't displayed. The Task Manager adds an information bar\non the Quick Settings display to inform users of the apps running in the\nbackground and their usage of phone resources such as memory and battery. With\nthis interface, users are notified if an app is running a foreground service for\na long time and can choose to stop an app. The affordance is placed on the\ndisplay in a subtle way so it doesn't obstruct important notifications. See\n[Task Manager](https://developer.android.com/about/versions/13/changes/fgs-manager)\nfor more information.\n\nImplement Task Manager for background apps\n------------------------------------------\n\nAlthough a [reference AOSP implementation](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/packages/SystemUI/src/com/android/systemui/qs/FgsManagerController.kt)\nfor this feature is available, Android-powered device implementers can customize and\nmodify this System UI.\nThe stop affordance in the Task Manager mustn't be displayed for apps which are\ncore to the functionality of the device, such as Dialer and Camera.\n\nThe AOSP implementation uses a new internal [callback API](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/app/IForegroundServiceObserver.aidl)\nbetween the [System UI](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/packages/SystemUI)\nand [System Server](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/services/core/java/com/android/server). This API lets the System Server notify the System UI when new\nforeground services are started. The API also notifies the System Server to\nstop certain apps, when requested by the user.\n| **Note:** This feature can't be turned off.\n\nValidate Task Manager for background apps notifications\n-------------------------------------------------------\n\nFor manual testing, validate the Task Manager feature against apps that are\nrunning in the background.\n\nFor unit testing, use [unit tests](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/FgsManagerControllerTest.java)\navailable in AOSP."]]