Skip to main content

Introduction

React Native Background Guardian provides a comprehensive API to prevent Android from killing background processes. The library offers methods for managing wake locks, battery optimizations, and OEM-specific settings.

Installation

Import Options

You can use either the default export or named exports:

TypeScript Support

The library is written in TypeScript and includes complete type definitions. All functions return typed promises:

Exported Interfaces

The library exports several TypeScript interfaces for type-safe development:

API Categories

Wake Lock Management

Control CPU wake locks to keep background tasks running:

Screen Wake Lock

Keep the screen on while the app is in the foreground:

Battery Optimization

Manage battery optimization exemptions:

Power Management

Monitor device power states:

OEM Settings

Access manufacturer-specific battery settings:

Platform Behavior

Most APIs are Android-specific:
  • Android: Full functionality as documented
  • iOS: Most methods are no-ops that return safe default values
iOS handles background execution differently through Background Modes configured in Xcode.

Basic Usage Pattern

Error Handling

All methods return boolean promises that resolve to false on error rather than throwing exceptions. This makes error handling straightforward: