expo-background-task
Version: 55.0.6
Expo Android and iOS module for Background Task APIs. Execute JavaScript code in the background even when the app is not active.
Installation
npx expo install expo-background-task expo-task-manager
Usage
import * as BackgroundTask from 'expo-background-task';
import * as TaskManager from 'expo-task-manager';
const TASK_NAME = 'background-task';
TaskManager.defineTask(TASK_NAME, async () => {
// Background work here
console.log('Background task executed');
return BackgroundTask.BackgroundTaskResult.Success;
});
await BackgroundTask.registerTaskAsync(TASK_NAME);
API Reference
Methods
registerTaskAsync(taskName, options)
(taskName: string, options?: BackgroundTaskOptions) => Promise<void>
Registers background task
unregisterTaskAsync(taskName)
(taskName: string) => Promise<void>
Unregisters background task
| Platform | Supported |
|---|
| iOS | ✅ |
| Android | ✅ |
| Web | ❌ |
Resources