Skip to main content

Background audio player

Use wake locks to keep the CPU running while playing audio in the background. This prevents the system from suspending your app during playback.
Always release the wake lock when you’re done with background work. Failing to release wake locks will drain the device battery.

Foreground kiosk / Always-on screen

Keep the screen on while your app is in the foreground. Perfect for kiosk applications, digital signage, or dashboards.
Screen wake locks only work while the app is in the foreground. For background CPU execution, use acquireWakeLock() instead.

Background location tracking

For reliable background location tracking, you need to request battery optimization exemptions and handle OEM-specific settings.
OEM-specific battery optimizations can kill your app even if standard Android battery optimizations are disabled. Always check for manufacturer-specific settings on Xiaomi, Huawei, Oppo, Vivo, and Samsung devices.

Complete integration example

This example shows a complete React hook that manages battery optimization status and provides a clean interface for your components.

Using the hook in your component

The hook automatically refreshes battery optimization status when the app returns to the foreground, ensuring your UI always shows the current state.