Skip to main content

Overview

React Native Background Guardian is primarily designed for Android, where aggressive battery optimizations can kill background processes. On iOS, the library provides a safe no-op implementation that returns appropriate default values.

API behavior comparison

Wake lock management

On Android, wake locks are reference-counted. Each acquireWakeLock() call must be paired with a releaseWakeLock() call.

Screen wake lock

Screen wake locks do NOT keep the CPU running in the background. They only prevent the screen from turning off while the app is visible. For background work, use acquireWakeLock().

Battery optimization

Google Play restricts use of REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission. Only use requestBatteryOptimizationExemption() if your app genuinely requires background execution (messaging, health tracking, device management, etc.). Otherwise, use openBatteryOptimizationSettings().

Power save mode

Power Save mode is different from battery optimization exemptions. An app can be exempt from Doze mode but still be affected by Power Save mode restrictions.

Device idle mode (Doze)

OEM-specific settings

When to use each API

Background audio/video playback

Foreground-only screen keep-awake

Both platforms support screen wake locks with the same API. This is one of the few methods that has meaningful behavior on both platforms.

Background location tracking

Cross-platform best practices

Always check platform before showing UI

Safe to call on all platforms

All methods are safe to call on both platforms. iOS will return appropriate default values:

Handle platform-specific requirements separately