部分 Wake Lock 是 PowerManager API 中的一項機制,可以讓開發人員在關閉裝置螢幕 (無論是因為系統逾時還是因為使用者按下電源鍵) 之後繼續運行 CPU。應用程式可以使用 PARTIAL_WAKE_LOCK 標記呼叫 acquire(),或使用其他可取得 Wake Lock 的 API,取得部分 Wake Lock。過度使用部分 Wake Lock 會耗盡裝置電量,因為這會阻止裝置進入電量較低的狀態。您應只在必要時使用部分 Wake Lock,並於不再需要時立即釋放。
[[["容易理解","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,["# Excessive partial wake locks (beta)\n\nPartial wake locks are a mechanism in the [`PowerManager`](/reference/android/os/PowerManager) API that lets\ndevelopers keep the CPU running after a device's display turns off (whether due\nto system timeout or the user pressing the power button). Your app acquires a\npartial wake lock by calling [`acquire()`](/reference/android/os/PowerManager.WakeLock#acquire()) with the [`PARTIAL_WAKE_LOCK`](/reference/android/os/PowerManager#PARTIAL_WAKE_LOCK)\nflag, or by using [other APIs that acquire wake locks](/develop/background-work/background-tasks/awake/wakelock/identify-wls).\nExcessive use of partial wake locks drains the device's battery because it\nprevents the device from entering lower power states. Partial wake locks should\nbe used only when necessary and released as soon as no longer needed.\n\nIf your app uses partial wake locks excessively, you can use the guidance in\nthis page to diagnose and fix the problem.\n\nYour feedback is a crucial part of improving our documentation. Please give us\nyour feedback using the following link:\n\n\n[Give feedback](https://docs.google.com/forms/d/e/1FAIpQLScYkStao0zVsmPay22DGqYEMJSf2Rk3SE3LnPc1lcmLjN1AiQ/viewform?usp=dialog)\n\nDetect the problem\n------------------\n\nAndroid vitals can help you find out when your app's use of partial wake locks\nis excessive.\n\n### Android vitals\n\nAndroid vitals can help improve your app's performance by [alerting you via the\nPlay Console](https://support.google.com/googleplay/android-developer/answer/9844486?) when your app's use of partial wake locks is\nexcessive.\n| **Note:** Tracking of excessive partial wake locks is **currently in beta**. The threshold numbers, relevant app states, and exceptions for behavior that has end-user benefit, are all subject to change. The beta metric does not currently make your app less discoverable on Google Play. Once the metric is out of beta, excessive partial wake lock use may impact app discoverability on Play.\n\nAndroid vitals reports partial wake lock use as **excessive** when **all of the\npartial wake locks**, added together, run for 3 or more hours in 24-hour\nperiod.\n\nAndroid vitals tracks time only if the wake lock is held when the app **is in\nthe background** and **does not have a foreground service**.\n\nAndroid vitals gives some exemptions to partial wake lock usage in scenarios\nwhere there is a clear user benefit of the partial wake lock, and there's no\nbetter way to achieve that result without the partial wake lock. In those cases,\nAndroid vitals might not count the partial wake lock time against the 3-hour\nlimit. For example, if an app is playing audio for the user, there's a clear\nbenefit to keeping the device awake and there's no way to play the audio without\nkeeping the device awake. In that case, the partial wake lock time is not\ncounted against the Android vitals.\n\nIf excessive partial wake locks occur in more than 5% of app sessions across all\ndevices in a 28-day period, it can affect your app's visibility on Play once the\nmetric is out of beta.\n\nOnce you're aware that your app has excessive partial wake locks,\nyour next step is to address the issue.\n\nFix the problem\n---------------\n\nBecause wake locks can drain the device battery, you shouldn't use wake\nlocks if there's an alternative. The\n[Choose the right API to keep the device awake](/develop/background-work/background-tasks/awake)\ndocumentation can help you find the best solution for your app.\n\nIf you do need to use a wake lock, [follow wake lock best practices](/develop/background-work/background-tasks/awake/wakelock/best-practices)\nto make sure your wake locks don't hurt device efficiency. In particular,\nmake sure every device you acquire is released, and release the lock as quickly\nas possible.\n\nAfter fixing the problem in code, you can verify your fixes by using [local\nwake lock debugging tools](/develop/background-work/background-tasks/awake/wakelock/debug-locally).\n\nSee also\n--------\n\n- [Stuck partial wake locks](/topic/performance/vitals/excessive-wakelock)\n- [Wake lock documentation](/develop/background-work/background-tasks/awake/wakelock)\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Frozen frames](/topic/performance/vitals/render#frozen-frames)\n- [Run benchmarks in Continuous Integration](/topic/performance/benchmarking/benchmarking-in-ci)\n- [Create and measure Baseline Profiles without Macrobenchmark](/topic/performance/baselineprofiles/manually-create-measure)"]]