Use this file to discover all available pages before exploring further.
Keep Your React Native Apps Alive in the Background
Prevent Android from killing background processes with Wake Locks, battery optimization exemptions, and OEM-specific protections. iOS-safe with no-op implementation.
Get your app protected from background restrictions in minutes
1
Install the package
Add React Native Background Guardian to your project using your preferred package manager:
npm install react-native-background-guardian
For iOS, install pods:
cd ios && pod install
2
Import and use wake locks
Import the library and acquire a wake lock to keep the CPU running during background tasks:
import BackgroundGuardian from 'react-native-background-guardian';// Acquire wake lock before starting background workconst acquired = await BackgroundGuardian.acquireWakeLock('MyBackgroundTask');if (acquired) { // Perform your background work await doBackgroundWork(); // Release when done await BackgroundGuardian.releaseWakeLock();}
3
Request battery optimization exemption
Check if your app is exempt from battery optimizations and request exemption if needed:
// Check current statusconst isIgnoring = await BackgroundGuardian.isIgnoringBatteryOptimizations();if (!isIgnoring) { // Show the system dialog to request exemption await BackgroundGuardian.requestBatteryOptimizationExemption();}
Google Play has restrictions on using REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Only use this if your app genuinely requires background execution (messaging, health tracking, device management, etc.).
4
Handle OEM-specific restrictions
Many manufacturers (Xiaomi, Huawei, Samsung) have additional battery optimization. Guide users to whitelist your app: