Android 16 平台包含一些行为变更,这些变更可能会影响您的应用。以下行为变更将影响在 Android 16 上运行的所有应用,无论采用哪种 targetSdkVersion
都不例外。您应该测试您的应用,然后根据需要进行修改,以支持这些变更(如果适用)。
此外,请务必查看仅影响以 Android 16 为目标平台的应用的行为变更列表。
核心功能
Android 16 包含以下更改,用于修改或扩展 Android 系统的各种核心功能。
JobScheduler 配额优化
Starting in Android 16, we're adjusting regular and expedited job execution runtime quota based on the following factors:
- Which app standby bucket the application is in: in Android 16, active standby buckets will start being enforced by a generous runtime quota.
- If the job starts execution while the app is in a top state: in Android 16, Jobs started while the app is visible to the user and continues after the app becomes invisible, will adhere to the job runtime quota.
- If the job is executing while running a Foreground Service: in Android 16, jobs that are executing while concurrently with a foreground service will adhere to the job runtime quota. If you're leveraging jobs for user initiated data transfer, consider using user initiated data transfer jobs instead.
This change impacts tasks scheduled using WorkManager, JobScheduler, and
DownloadManager. To debug why a job was stopped, we recommend logging why your
job was stopped by calling WorkInfo.getStopReason()
(for
JobScheduler jobs, call JobParameters.getStopReason()
).
For more information on battery-optimal best practices, refer to guidance on optimize battery use for task scheduling APIs.
We also recommend leveraging the new
JobScheduler#getPendingJobReasonsHistory
API introduced in
Android 16 to understand why a job has not executed.
Testing
To test your app's behavior, you can enable override of certain job quota optimizations as long as the app is running on an Android 16 device.
To disable enforcement of "top state will adhere to job runtime quota", run the
following adb
command:
adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_TOP_STARTED_JOBS APP_PACKAGE_NAME
To disable enforcement of "jobs that are executing while concurrently with a
foreground service will adhere to the job runtime quota", run the following
adb
command:
adb shell am compat enable OVERRIDE_QUOTA_ENFORCEMENT_TO_FGS_JOBS APP_PACKAGE_NAME
To test certain app standby bucket behavior, you can set the app standby bucket
of your app using the following adb
command:
adb shell am set-standby-bucket APP_PACKAGE_NAME active|working_set|frequent|rare|restricted
To understand the app standby bucket your app is in, you can get the app standby
bucket of your app using the following adb
command:
adb shell am get-standby-bucket APP_PACKAGE_NAME
完全弃用 JobInfo#setImportantWhileForeground
JobInfo.Builder#setImportantWhileForeground(boolean)
方法用于在调度应用位于前台或暂时豁免于后台限制时指示作业的优先级。
自 Android 12(API 级别 31)起,此方法已废弃。从 Android 16 开始,它不再有效,系统会忽略调用此方法。
此功能移除也适用于 JobInfo#isImportantWhileForeground()
。从 Android 16 开始,如果调用该方法,该方法会返回 false
。
用户体验和系统界面
Android 16 进行了以下变更,旨在打造更一致、更直观的用户体验。
废弃干扰性无障碍功能播报
Android 16 废弃了无障碍功能通告,其特征是使用 announceForAccessibility
或调度 TYPE_ANNOUNCEMENT
无障碍功能事件。这可能会给 TalkBack 和 Android 屏幕阅读器用户带来不一致的用户体验,而替代方案可以更好地满足各种 Android 辅助技术的用户需求。
替代方案示例:
- 对于窗口更改等重大界面更改,请使用
Activity.setTitle(CharSequence)
和setAccessibilityPaneTitle(java.lang.CharSequence)
。在 Compose 中,使用Modifier.semantics { paneTitle = "paneTitle" }
- 如需向用户告知关键界面的更改,请使用
setAccessibilityLiveRegion(int)
。在 Compose 中,请使用Modifier.semantics { liveRegion = LiveRegionMode.[Polite|Assertive]}
。应谨慎使用这些事件,因为它们可能会在每次更新视图时生成通知。 - 如需向用户发送错误通知,请发送类型为
AccessibilityEvent#CONTENT_CHANGE_TYPE_ERROR
的AccessibilityEvent
并设置AccessibilityNodeInfo#setError(CharSequence)
,或使用TextView#setError(CharSequence)
。
已废弃的 announceForAccessibility
API 的参考文档中包含有关建议替代方案的更多详细信息。