What are background tasks in React Native?
Answer
Background tasks allow React Native apps to execute code when the app is not in the foreground. Mobile OSes heavily restrict background execution for battery life. Types of background work: (1) Background fetch (periodic): OS wakes app periodically to fetch new data. Not real-time — typically 15 minutes minimum interval: npm install react-native-background-fetch import BackgroundFetch from "react-native-background-fetch"; BackgroundFetch.configure({ minimumFetchInterval: 15 }, async taskId => { await syncData(); BackgroundFetch.finish(taskId); }, taskId => { BackgroundFetch.finish(taskId); });; (2) Background notifications: push notifications can include data payload and trigger background processing when received; (3) Background download/upload: iOS allows background URLSession for transfers that continue when app is backgrounded. Android similar with WorkManager; (4) Geofencing and location: background location updates (requires special permission justification); (5) React Native Headless JS (Android): run JS code in background when app is not running — for GCM background messages. AppState API: import { AppState } from "react-native"; const subscription = AppState.addEventListener("change", state => { // "active", "background", "inactive" (iOS only) if (state === "background") saveState(); if (state === "active") refreshData(); });. Limitations: iOS is very restrictive — background execution is limited to ~30 seconds for most task types. Android is more permissive but still has Doze mode and App Standby restrictions. Always test background behavior on real devices.
Previous
What is Flipper in React Native?
Next
What is react-native-reanimated Shared Values and Worklets?
More React Native Questions
View all →- Intermediate What is the React Native New Architecture?
- Intermediate What is React Navigation nested navigators?
- Intermediate How do you handle network requests in React Native?
- Intermediate What are Native Modules in React Native?
- Intermediate What is the difference between react-native-reanimated and the Animated API?