管理裝置的喚醒狀態
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 裝置閒置時,會先調暗螢幕,然後關閉螢幕,最後關閉 CPU。避免裝置電池快速耗盡。不過,有時應用程式可能需要不同的行為:
- 遊戲或電影等應用程式可能需要讓螢幕保持開啟。
- 其他應用程式可能不需要螢幕保持開啟,但可能需要 CPU 持續運作,直到完成重要作業為止。
這些課程說明如何在必要時讓裝置保持喚醒狀態,同時避免耗盡電量。
課程
- 讓裝置保持喚醒狀態
- 瞭解如何視需要讓螢幕或 CPU 保持喚醒狀態,同時盡量減少對電池續航力的影響。
- 設定鬧鐘
- 瞭解如何使用重複鬧鐘安排作業,即使應用程式未執行或裝置處於休眠狀態,這些作業仍會在應用程式生命週期外執行。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-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-08-27 (世界標準時間)。"],[],[],null,["When 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**[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."]]