React Native · APIs and utilities
Background tasks
Background tasks.
7 exports
Import
BackgroundTask
moduleBackground tasks. Define the handler in the app's root file (index.js, outside components): when the app is started in the background it runs without rendering the screen.
| Name | Type | Description |
|---|---|---|
define | (name: string, handler: BackgroundTaskHandler) => void | Defines a task handler. Defining again with the same name replaces the previous one. |
defined | () => string[] | Defined task names. |
schedule | (name: string, options?: BackgroundScheduleOptions) => Promise<void> | Runs the task periodically. On Android it survives device restarts. On iOS the task name must be in the ui.config background.tasks list; the simulator does not support it (E_BACKGROUND). |
cancel | (name: string) => Promise<void> | Removes the schedule. |
getScheduled | () => Promise<ScheduledBackgroundTask[]> | Scheduled tasks. |
runNow | (name: string) => Promise<void> | Runs the task now (for testing). On Android it goes through the real background path (JobScheduler + headless JS). |
status | () => Promise<BackgroundStatus> | Background execution permission (iOS: Settings > Background App Refresh). |
BackgroundReason
typeWhy the task is running.
BackgroundTaskContext
interfaceWhat the task handler receives.
| Name | Type | Description |
|---|---|---|
name | string | Task name. |
reason | BackgroundReason | Why the task runs. |
expired | boolean | Becomes true when the time iOS granted runs out; stop long work here. |
Task handler; the task ends when the returned Promise settles.
BackgroundScheduleOptions
interfaceOptions for BackgroundTask.schedule.
| Name | Type | Default | Description |
|---|---|---|---|
interval? | number | 15 | Minimum interval (minutes, at least 15). The system may delay it based on battery and usage; exact timing is not guaranteed. |
network? | "none" | "any" | "unmetered" | "none" | Network condition: any any connection, unmetered Wi-Fi. |
charging? | boolean | false | Only while charging. |
startOnBoot? | boolean | false | Android: also run right away when the device boots and when the app is updated (even if the app is not opened). No equivalent on iOS. |
ScheduledBackgroundTask
interfaceScheduled task.
| Name | Type | Description |
|---|---|---|
name | string | Task name. |
interval | number | Minimum interval between runs (minutes). |
network | string | null | Required network type; null if none is required. |
charging | boolean | Runs only while charging. |
startOnBoot | boolean | Scheduled again after the device restarts. |
pending | boolean | Whether it is pending in the system. |
BackgroundStatus
typeCan it run in the background: the iOS user setting (Background App Refresh); unavailable on the iOS simulator. Always available on Android.