Overview
Acquires a partial wake lock to keep the CPU running while the screen is off. This prevents the Android system from suspending the CPU, allowing background tasks to continue running.Parameters
Optional identifier for the wake lock. Useful for debugging and identifying which component holds the lock in system logs.
Optional timeout in milliseconds after which the wake lock will be automatically released. Defaults to 24 hours (86400000ms).
Returns
Promise resolving to
true if the wake lock was successfully acquired, false otherwise.Platform Behavior
| Platform | Behavior |
|---|---|
| Android | Acquires a PARTIAL_WAKE_LOCK that keeps the CPU running. The library manages a single wake lock - if a wake lock is already held, subsequent calls return true without acquiring another lock. |
| iOS | No-op that returns true immediately. iOS handles background execution differently through Background Modes. |
Important Notes
- Single Wake Lock Model: The library maintains a single wake lock instance. If you call
acquireWakeLock()while a lock is already held, it returnstruewithout creating a duplicate. Always callreleaseWakeLock()when your background work is complete. - Battery Impact: Holding wake locks prevents the device from sleeping, which can drain battery. Use timeouts and release locks promptly.
- Permission Required: Requires
android.permission.WAKE_LOCKin AndroidManifest.xml (automatically added by the library).
Example Usage
Basic Usage
With Custom Timeout
With Error Handling
Checking Before Acquiring
Related APIs
releaseWakeLock()- Release the wake lockisWakeLockHeld()- Check if wake lock is heldenableScreenWakeLock()- Keep screen on (different from CPU wake lock)

