코드가 절전 모드 해제 잠금 객체를 만들 때 클래스의 이름을 절전 모드 해제 잠금 태그의 일부로 사용합니다. wake lock 태그의 일부로 패키지, 클래스 또는 메서드 이름을 포함하는 것이 좋습니다. 이렇게 하면 오류가 발생할 경우 소스 코드에서 절전 모드 해제 잠금을 더 쉽게 찾을 수 있습니다. 자세한 내용은 절전 모드 해제 잠금 이름 올바르게 지정을 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-30(UTC)
[[["이해하기 쉬움","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-30(UTC)"],[],[],null,["You can set a *wake lock* to temporarily keep the device awake.\n| **Note:** Creating and holding wake locks can have a dramatic impact on the device's battery life. You shouldn't use wake locks if there are any suitable alternatives. For other options, see the [Choose the right API to keep the device awake](/develop/background-work/background-tasks/awake) documentation. If you do need to use a wake lock, make sure to hold it for as short a time as possible.\n\nDependencies\n\nYour app must have the [`WAKE_LOCK`](/reference/android/Manifest.permission#WAKE_LOCK) permission to set a wake lock.\nAdd the permission to your app's manifest: \n\n \u003cuses-permission android:name=\"android.permission.WAKE_LOCK\" /\u003e\n\nCreate and acquire a wake lock\n\nTo acquire a wake lock, do the following:\n\n1. Call [`PowerManager.newWakeLock()`](/reference/android/os/PowerManager#newWakeLock(int,%20java.lang.String)) to create a wake lock.\n This creates and configures a `PowerManager.WakeLock` object but does not\n actually keep the device awake.\n\n2. When you want to keep the device awake, call the wake lock object's\n [`acquire()`](/reference/android/os/PowerManager.WakeLock#acquire()) method.\n\nFor example, if your app includes a broadcast receiver that uses a service to do\nsome work, you can use this code to set and acquire a wake lock:\n\n\nKotlin \n\n```kotlin\nval wakeLock: PowerManager.WakeLock =\n (getSystemService(Context.POWER_SERVICE) as PowerManager).run {\n newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, \"MyClassName::MyWakelockTag\").apply {\n acquire()\n }\n }https://github.com/android/snippets/blob/f95ab59fad80aeaf5d6a90bab8a01a126f20f44e/misc/src/main/java/com/example/snippets/backgroundwork/WakeLockSnippetsKotlin.kt#L28-L33\n```\n\nJava \n\n```java\nPowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);\nPowerManager.WakeLock wakeLock =\n powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, \"MyClassName::MyWakelockTag\");\nwakeLock.acquire();https://github.com/android/snippets/blob/f95ab59fad80aeaf5d6a90bab8a01a126f20f44e/misc/src/main/java/com/example/snippets/backgroundwork/WakeLockSnippetsJava.java#L17-L20\n```\n\n\u003cbr /\u003e\n\nKey points about this code\n\nWhen the code creates the wake lock object, it uses the class's name as part\nof the wake lock tag. We recommend including your package, class, or method name\nas part of the wake lock tag. That way, if an error occurs, it's easier to\nlocate the wake lock in your source code. For more information, see\n[Name the wake lock properly](/develop/background-work/background-tasks/awake/wakelock/best-practices#name).\n\nSee also\n\n- [Release a wake lock](/develop/background-work/background-tasks/awake/wakelock/release)\n- [Follow wake lock best practices](/develop/background-work/background-tasks/awake/wakelock/best-practices)"]]