Series · 8 parts · 41 min
WorkManager in Production
Background work that survives process death, flaky networks and big data sets: workers, dependency graphs, progress and failure contracts.
- Part 01Injecting Dependencies into WorkManager Workers with HiltWorkManager creates workers through its own factory, which means constructor injection fails silently unless you replace that factory with Hilt's. This post covers @HiltWorker, @AssistedInject, and HiltWorkerFactory setup from scratch.5 min read
- Part 02WorkerTags — A Central Contract Between WorkManager Scheduler and UI ObserverString literals scattered across worker enqueue calls and UI observers are a silent refactoring hazard. A single WorkerTags object makes the contract explicit, type-safe at call sites, and audit-friendly.5 min read
- Part 03Seeding a Room Database with a WorkManager Phased Dependency GraphNaively enqueuing all import workers at once causes foreign-key failures. This post covers a production dependency graph using WorkManager chaining to seed Room in correct order.5 min read
- Part 04A Base Worker Template for Batched Room Inserts with Retry and ProgressDuplicating notification logic and batch-insert boilerplate across seven WorkManager workers is how bugs hide. This post covers an abstract base class that reduces each worker to three overrides while handling batching, retries, backup recovery, and progress notifications centrally.6 min read
- Part 05Orchestrating Android DownloadManager from a WorkManager CoroutineWorkerWorkManager handles lifecycle and retry logic. DownloadManager handles reliable HTTP transfers. Used together, each does what it is good at. This post covers the coroutine polling loop that bridges them in production.5 min read
- Part 06Protecting Downloaded Files with a Rename-to-Backup StrategyAn interrupted download leaves a corrupt or missing file. Renaming the previous version to .bak before the new download starts gives the database seeding worker a fallback — without any network retry.5 min read
- Part 07Passing Structured Failure Data Out of a WorkManager WorkerResult.failure() tells the UI a worker failed. It does not tell the UI what failed. workDataOf() attaches typed output to a failure result so the caller knows exactly which files were not downloaded.5 min read
- Part 08Bridging WorkManager and Compose UI via a Listener-based ProgressRepositoryWorkManager's built-in setProgress() emits untyped Data blobs. A listener-based ProgressRepository converts worker callbacks into a typed domain model that flows directly into Compose StateFlow without polling.5 min read