Background Tasks & App States
What apps can and cannot do in the background on Android and iOS, and how to schedule sync, uploads and periodic work reliably.
Advanced · about 6 hours · difficulty 4/5
Learn first: Offline-first & Data Synchronisation
Desktop programs can run whenever they like; mobile apps cannot. Both OSes aggressively limit background execution to save battery, and the rules differ.
The rules in brief
- iOS: apps are suspended shortly after leaving the foreground. Allowed exceptions include background fetch/refresh (
BGAppRefreshTask), processing tasks (BGProcessingTask, often while charging), background URL sessions for uploads/downloads, audio, location and VoIP. The system decides when scheduled tasks actually run. - Android: Doze and app standby restrict background work. Use WorkManager for deferrable, guaranteed work with constraints (network, charging), and foreground services with a visible notification for user-visible ongoing tasks like navigation or music.
Cross-platform tools
expo-background-task and expo-task-manager in React Native; workmanager in Flutter.
Designing for it
- Assume background work may be delayed, batched or skipped; make it idempotent and resumable.
- Prefer server-driven approaches (silent push to trigger a sync, server-side processing) over polling.
- Sync when the app returns to the foreground as a reliable fallback.
Pitfalls
Expecting a timer to fire every 15 minutes exactly on iOS. It will not.
Good enough to move on: your offline outbox syncs through a scheduled background task and also on app foreground.
Key concepts
- iOS background modes
- BGTaskScheduler
- Android Doze and app standby
- WorkManager
- Foreground services
- Background uploads and downloads
- Silent push to trigger sync
Mini project
Add a background sync task to your offline-first expense tracker and log each run with a timestamp to observe how often each OS actually runs it.
Check yourself
Why can't you rely on a background task running at an exact interval on iOS, and what do you do instead?
Free resources
- Android: Background work with WorkManager (Android Developers)
- Apple Background Tasks (Apple)
- Expo BackgroundTask (Expo)