自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
任务管理器
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 Android 13 中,一项新的系统界面选项(称为任务管理器)会通知用户后台应用的前台服务的状态和所使用的资源,并且可让用户停止这些应用。
随着 Android 13 中推出通知权限功能,用户能够自主关闭运行前台服务的后台应用发出的有关以下方面的通知:位置信息、媒体播放和投影、数据同步、视频和语音通话以及连接的设备。关闭此类通知后,系统就不会显示前台服务向用户发送的指示其状态和资源使用情况的必需通知。任务管理器在“快捷设置”屏幕上添加了一个信息栏,用于告知用户在后台运行的应用及其使用手机资源(如内存和耗电量)的情况。借助此界面,用户会在应用长时间运行前台服务时收到通知,并且可以选择停止应用。此选项在屏幕上的放置位置非常巧妙,不会妨碍重要通知的显示。如需了解详情,请参阅任务管理器。
为后台应用实现任务管理器
虽然已推出此功能的参考 AOSP 实现,但搭载 Android 的设备实现者可以自定义和修改此系统界面。某些应用(例如拨号器和相机)是设备功能的核心,不得在任务管理器中显示停止选项。
AOSP 实现会在系统界面和系统服务器之间使用新的内部 callback API。使用此 API,系统服务器可以在系统启动新的前台服务时通知系统界面。此 API 还会应用户请求通知系统服务器停止某些应用。
验证用于后台应用通知的任务管理器
对于手动测试,请针对在后台运行的应用验证任务管理器功能。
对于单元测试,请使用 AOSP 中提供的单元测试。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-05。
[null,null,["最后更新时间 (UTC):2025-03-05。"],[],[],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."]]