FULL AI ANALYSIS

Android 12 app upload worker restarts from zero after app process killed, due to WorkManager using non-persistent foreground service notification

Generated Oct 3, 2026, 12:35:03 AM

Analysis summary

The core issues are: (1) using app-internal cache for partial upload state which the OS may reclaim on process kill, and (2) treating WorkManager inputData/one-time work in a way that replaces lost runs instead of resuming. WorkManager will attempt to restart interrupted work, but if the worker's state (temp file, local offsets) was stored in volatile cache or in-memory, the resumed worker has no state to continue from. The foreground notification and WorkManager policy alone don't guarantee persistence of intermediate upload state across process restarts. A resumable upload requires persistent state (on-disk) and an idempotent protocol on the server or support for byte-range/resumable APIs.

Possible causes

Partial upload state was stored in app cache (volatile) which the system may purge when killing the process, preventing resumption.

95%

WorkManager's ExistingWorkPolicy.REPLACE or ambiguous unique naming causes new work to start instead of resuming previous run.

80%

Foreground notification not correctly tied to a persistent foreground service, leading the OS to deprioritize the process and kill it under memory pressure.

60%

Upload protocol/server does not support resuming or range appends; client attempts to restart from zero when no resume token stored.

20%

Suggested fixes

1

Diagnostic step 1

Use a durable storage location for partial upload state: write progress metadata (upload ID, byte offset, temp file path) to a database (Room) or to files in getExternalFilesDir so they survive process kill and are not auto-pruned by the system.

2

Diagnostic step 2

Implement or use a resumable upload protocol (e.g., tus.io, HTTP range uploads, or server-provided upload-id and offset) so the client can query server for current offset and resume from where it left off.

3

Diagnostic step 3

Configure WorkManager to use unique work with ExistingWorkPolicy.KEEP and design your worker to detect an existing incomplete upload by reading persistent metadata; on launch, the worker should query server for upload offset and resume streaming from that offset.

4

Diagnostic step 4

If long-running foreground behavior is essential, use WorkManager's foreground worker correctly by creating a NotificationChannel and calling setForegroundAsync early in doWork(), and ensure the notification is persistent and consistent so the system honors the foreground priority.

5

Diagnostic step 5

Test under aggressive memory pressure scenarios and verify that persisted metadata is available after process restarts. Consider using a foreground Service in combination with WorkManager only for critical uploads, and document to users that very large uploads may be paused if the OS kills the app in extreme conditions.