管理设备唤醒状态
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
当 Android 设备空闲时,它会首先调暗屏幕,然后关闭屏幕,最终关闭 CPU。这可以防止设备的电池电量快速耗尽。不过,有时您的应用可能需要采取不同的行为:
- 游戏或电影应用等应用可能需要使屏幕保持开启状态。
- 其他应用可能不需要屏幕始终处于开启状态,但可能需要 CPU 持续运行,直到某项关键操作完成。
以下课程介绍了如何在必要时使设备保持唤醒状态,而不大量消耗电池电量。
课程
- 使设备保持唤醒状态
- 了解如何根据需要使屏幕或 CPU 保持唤醒状态,同时最大限度减少对电池续航时间的影响。
- 设置闹钟
- 了解如何使用重复闹钟来安排在应用生命周期之外定期执行操作(即使应用未运行或设备处于休眠状态)。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Manage device awake state\n\nWhen an Android-powered device is left idle, it will first dim, then turn off the\nscreen, and ultimately turn off the CPU. This prevents the device\\\\'s battery\nfrom quickly getting drained. Yet there are times when your application might\nrequire a different behavior:\n\n- Apps such as games or movie apps may need to keep the screen turned on.\n- Other applications may not need the screen to remain on, but they may require the CPU to keep running until a critical operation finishes.\n\nThese lessons describe how to keep a device awake when necessary without\ndraining its battery.\n\nLessons\n-------\n\n**[Keep the device awake](/develop/background-work/background-tasks/scheduling/wakelock)**\n: Learn how to keep the screen or CPU awake as needed, while minimizing the\n impact on battery life.\n\n**[Schedule alarms](/develop/background-work/services/alarms/schedule)**\n: Learn how to use repeating alarms to schedule operations that take place\n outside of the lifetime of the application, even if the application is not\n running or the device is asleep."]]