← ClaudeAtlas

android-workmanagerlisted

WorkManager patterns for Android - background sync, unique work, constraints, retries, periodic jobs, worker injection, and observing work state from the app. Use this skill whenever scheduling deferrable background work, syncing local and remote data, retrying uploads, or running tasks that must survive process death. Trigger on phrases like "WorkManager", "background sync", "periodic work", "retry upload", "constraints", "CoroutineWorker", "enqueueUniqueWork", or "observe work info".
lenorebreakneck630/claude-zero-to-hero-android-KMP · ★ 1 · AI & Automation · score 64
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android WorkManager ## When to Use It Use WorkManager for work that is: - deferrable - guaranteed eventually - expected to continue across app restarts or process death - constrained by network, charging, battery, or storage conditions Do **not** use WorkManager for: - immediate in-app UI actions - work that must finish while the screen is visible only - exact alarms - long-running foreground media playback --- ## Core Principles - Workers must be **idempotent** — safe to run more than once. - Prefer **unique work** so duplicate jobs do not pile up. - Keep business logic in domain/data classes; the worker only coordinates execution. - Return `Result.retry()` only for failures that may succeed later. - Pass IDs and lightweight flags through `Data`, not large payloads. --- ## Worker Structure Use `CoroutineWorker` for suspending APIs: ```kotlin class SyncNotesWorker( appContext: Context, params: WorkerParameters, private val noteRepository: NoteRepository ) : CoroutineWorker(appContext, params) { override suspend fun doWork(): Result { return when (noteRepository.sync()) { is com.example.core.domain.Result.Success -> Result.success() is com.example.core.domain.Result.Error -> Result.retry() } } } ``` Map typed domain/data failures to WorkManager results intentionally: - temporary network failure -> `Result.retry()` - invalid input or permanent server rejection -> `Result.failure()` - success -> `Result.su