The Challenge of Background Work
Mobile operating systems aggressively limit what apps can do in the background to preserve battery life and system resources. Unlike servers or desktop apps, mobile apps cannot simply run indefinitely. Both iOS and Android have progressively tightened background execution restrictions over the years.
Understanding these limits is essential. If you fight the platform, your background tasks will be killed, your app may be penalized, and users will see excessive battery drain.
iOS Background Processing
iOS is more restrictive than Android about background execution. By default, when your app moves to the background, it has approximately 5-10 seconds before it is suspended.
Background Modes
To do meaningful background work, declare specific background modes in Info.plist:
- Background fetch: Periodically wake the app to fetch small amounts of data
- Remote notifications: Silent push notifications wake the app for data processing
- Background processing: Run longer tasks during optimal conditions (device charging, Wi-Fi)
- Audio: Continue playing audio in the background
- Location: Receive location updates in the background
BGTaskScheduler (iOS 13+)
The modern way to schedule background work on iOS:
- BGAppRefreshTask: Short tasks (up to 30 seconds) for periodic data refresh
- BGProcessingTask: Longer tasks (minutes) that run when the device is idle and charging
The system decides when to execute your tasks based on device conditions, battery level, and usage patterns. You request execution, but Apple determines the timing.
Key Limitations
- Background tasks are not guaranteed to run at all
- The system learns user patterns and may skip tasks if the user rarely opens your app
- Processing tasks only run when the device is charging
Android Background Processing
Android offers more background execution options but has also tightened restrictions since Android 8 (Oreo).
WorkManager
The recommended solution for deferrable, reliable background work:
- OneTimeWorkRequest: Run once
- PeriodicWorkRequest: Run at regular intervals (minimum 15 minutes)
- Chained work: Sequential or parallel task chains
- Survives app restarts and device reboots
- Respects battery optimization and Doze mode
WorkManager is the most reliable way to do background work on Android.
Foreground Services
For tasks the user is actively aware of (music playback, navigation, active downloads):
- Must display a persistent notification
- Can run for extended periods
- Android 14+ requires declaring the foreground service type in the manifest
Doze and App Standby
Android's battery optimization features affect background work:
- Doze mode: When the device is stationary and screen is off, the system defers background work and network access
- App Standby Buckets: Apps are categorized by usage frequency (Active, Working Set, Frequent, Rare, Restricted), each with different limits
Cross-Platform Approaches
React Native
- expo-background-fetch: Cross-platform periodic background fetch
- expo-task-manager: Define and manage background tasks
- For reliable work, consider native modules using WorkManager (Android) and BGTaskScheduler (iOS) directly
Flutter
- workmanager package: Dart wrapper around Android WorkManager and iOS BGTaskScheduler
- flutter_background_service: Keep a Dart isolate running in the background
Practical Use Cases
Syncing Data
Use background fetch (iOS) or periodic WorkManager (Android) to sync local changes to the server. Always implement conflict resolution and handle offline scenarios.
Downloading Content
Use platform download managers (URLSession background transfer on iOS, DownloadManager on Android) for large file downloads. These continue even when the app is killed.
Location Tracking
Requires explicit user permission and background location capability. Both platforms restrict continuous background location to apps with clear user-facing reasons. Apple requires a justification string that reviewers scrutinize during App Review.
Best Practices
- Minimize background work: Only do what is truly necessary in the background
- Be efficient: Complete tasks quickly and release resources
- Handle interruption: Your task can be killed at any time. Save progress incrementally.
- Respect battery: Users will uninstall apps that drain battery
- Test thoroughly: Background behavior differs between devices, OS versions, and battery states