Android 12 app upload worker restarts from zero after app process killed, due to WorkManager using non-persistent foreground service notification
Environment
App built with React Native (0.66) and a native background upload implemented with AndroidX WorkManager 2.7 on Android 12 (Pixel 5). Uploads are large (100+ MB). Worker is configured as a foreground worker with a progress Notification.
Symptoms
When the user switches to another app or the system kills the RN JS process under memory pressure, large background uploads restart from 0% on next launch; partial progress isn't resumed. Logs show the previous Work continuation failing with 'Interrupted' and a new WorkRequest starting with fresh input data.
Observations
WorkManager shows one-time work with unique name and ExistingWorkPolicy.REPLACE. The Worker creates a foreground notification via setForegroundAsync with NotificationCompat.Builder using the app's channel. The upload code writes to a temp file and streams to server in chunks, reporting progress via setForegroundAsync. When process is killed (system OOM), the Worker is restarted by WorkManager but the original temporary file was stored in app-cache (getCacheDir()) which may have been cleared by the system before restart. Additionally, the WorkRequest inputData includes the upload URL and file path; the file path pointed to cache/temporary file. Because policy is REPLACE and WorkManager recreates the job on restart, the partial bytes are lost.
Already attempted
Switched ExistingWorkPolicy to KEEP to prevent duplicate restarts — observed WorkManager still restarted a new Worker because the previous run was marked failed when process was killed. Moved temporary file to external storage (getExternalFilesDir) to survive process kill — uploads resumed when Worker restarted, but Android killed app more aggressively and the notification disappeared. Tried using ForegroundService directly — more complex and still suffered from cache cleanup.
Question
How can I implement robust resumable uploads that survive app process kills and restart by the system, using WorkManager/foreground services in Android 12, without requiring the user to manually restart uploads?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Mobile32% match
iOS app multipart upload restarts from zero when switching between 5G and Wi‑Fi during transfer (React Native background uploader)
Open0 answers - Mobile22% match
Flutter background sync stops on certain Android 13 OEM ROMs when device Doze enters aggressive standby
Open0 answers - Mobile21% match
React Native Android release APK crashes on cold start only when R8 minification is enabled — index.android.bundle missing at runtime
Open0 answers