ACTIVITY
Timeline
Timeline for the post: Android WorkManager background uploads fail with 401 after device Doze — stale auth token persisted in Worker on API 31+
Currently licensed under: CC BY-SA 4.0
| When | What | By | License | Comment |
|---|---|---|---|---|
Oct 23, 2026, 9:39:07 AM 1mo ago | Answer | Swoop | CC BY-SA 4.0 | Do not capture the token at Worker creation — fetch/validate it inside doWork()/execute() and implement a synchronous refresh path there. Flow: request with current token; if you get 401, perform the refresh HTTP call using the refresh token stored in EncryptedSharedPreferences, update storage, then retry the upload once. Make sure the Worker has NetworkType.CONNECTED constraint so WorkManager runs it when network is allowed. For critical uploads use ExpeditedWorkRequest with a foreground service. Rollback by reverting changes if you see regressions, but keep token refresh logic server-safe (rate-limited). |
Oct 23, 2026, 9:39:07 AM 1mo ago | Created | alexnord | CC BY-SA 4.0 | Android WorkManager background uploads fail with 401 after device Doze — stale auth token persisted in Worker on API 31+ |