Release a wake lock
Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to release a wake lock held by your app.
It's important to release a wake lock as soon as your app is
finished using it to avoid draining the battery.
Release an active wake lock
To release an active wake lock, call its release()
method. Doing so
releases your claim to the CPU.
For example, the following code acquires a wake lock,
does some work, then releases the wake lock:
Kotlin
@Throws(MyException::class)
fun doSomethingAndRelease() {
wakeLock.apply {
try {
acquire()
doTheWork()
} finally {
release()
}
}
}
Java
void doSomethingAndRelease() throws MyException {
try {
wakeLock.acquire();
doTheWork();
} finally {
wakeLock.release();
}
}
Make sure to release wake locks as soon as they are no longer needed. For
example, if you use a wake lock to allow a background task to finish, make sure
to release the lock as soon as the task finishes.
Key points about this code
In this example, the method doTheWork()
might throw an exception. For this
reason, the code releases the wake lock in the finally
block, to make sure
the wake lock is released whether or not an exception is thrown. It's very
important to make sure every wake lock you set is released, so you need to
check every possible code path to make sure the wake lock isn't left active
on any of them.
See also
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-13 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-13 UTC."],[],[],null,["# Release a wake lock\n\nThis page describes how to release a wake lock held by your app.\nIt's important to release a wake lock as soon as your app is\nfinished using it to avoid draining the battery.\n\nRelease an active wake lock\n---------------------------\n\nTo release an active wake lock, call its [`release()`](/reference/android/os/PowerManager.WakeLock#release()) method. Doing so\nreleases your claim to the CPU.\n\nFor example, the following code [acquires a wake lock](/develop/background-work/background-tasks/awake/wakelock/set),\ndoes some work, then releases the wake lock:\n\n\n### Kotlin\n\n```kotlin\n@Throws(MyException::class)\nfun doSomethingAndRelease() {\n wakeLock.apply {\n try {\n acquire()\n doTheWork()\n } finally {\n release()\n }\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/misc/src/main/java/com/example/snippets/backgroundwork/WakeLockSnippetsKotlin.kt#L42-L52\n```\n\n### Java\n\n```java\nvoid doSomethingAndRelease() throws MyException {\n try {\n wakeLock.acquire();\n doTheWork();\n } finally {\n wakeLock.release();\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/misc/src/main/java/com/example/snippets/backgroundwork/WakeLockSnippetsJava.java#L27-L34\n```\n\n\u003cbr /\u003e\n\nMake sure to release wake locks as soon as they are no longer needed. For\nexample, if you use a wake lock to allow a background task to finish, make sure\nto release the lock as soon as the task finishes.\n\n### Key points about this code\n\nIn this example, the method `doTheWork()` might throw an exception. For this\nreason, the code releases the wake lock in the `finally` block, to make sure\nthe wake lock is released whether or not an exception is thrown. It's very\nimportant to make sure every wake lock you set is released, so you need to\ncheck every possible code path to make sure the wake lock isn't left active\non any of them.\n\nSee also\n--------\n\n- [Set a wake lock](/develop/background-work/background-tasks/awake/wakelock/set)"]]