home / skills / hoangnguyen0403 / agent-skills-standard / background-work
This skill helps you implement robust Android background tasks using WorkManager, explicit constraints, Hilt integration, and foreground service guidelines for
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill background-workReview the files below or copy the command above to add this skill to your agents.
---
name: Android Background Work
description: Standards for WorkManager and Background Processing
metadata:
labels: [android, background, workmanager]
triggers:
files: ['**/*Worker.kt']
keywords: ['CoroutineWorker', 'WorkManager', 'doWork']
---
# Android Background Work Standards
## **Priority: P1**
## Implementation Guidelines
### WorkManager
- **CoroutineWorker**: Use for all background tasks.
- **Constraints**: Be explicit (Require Network, Charging).
- **Hilt**: Use `@HiltWorker` for DI integration.
### Foreground Services
- **Only When Necessary**: Use generating visible notifications only for tasks the user is actively aware of (Playback, Calls, Active Navigation). Otherwise use WorkManager.
## Anti-Patterns
- **IntentService**: `**Deprecated**: Use WorkManager.`
- **Short Jobs**: `**No short background jobs**: Use standard Coroutines in VM.`
## References
- [Worker Template](references/implementation.md)
This skill codifies standards for Android background work, focusing on WorkManager and safe foreground service usage. It prescribes CoroutineWorker, explicit constraints, and Hilt integration to ensure reliable, testable, and battery-friendly background processing. The guidance also highlights common anti-patterns to avoid and when to prefer in-process coroutines or foreground services.
The skill inspects background task definitions and recommends using WorkManager with CoroutineWorker as the default implementation for scheduled, deferrable, and guaranteed work. It enforces explicit constraints (network, charging, battery) and suggests using @HiltWorker for dependency injection. For user-visible continuous tasks, it recommends foreground services with visible notifications; for short-lived or UI-scoped work, it advises using coroutines in the ViewModel instead of background workers.
When should I use a foreground service instead of WorkManager?
Use a foreground service only for long-running tasks the user expects to see (media playback, active navigation, phone calls). For background work that does not require immediate user awareness, prefer WorkManager.
Can I still use IntentService or JobIntentService?
No. Those APIs are deprecated for most background work. Migrate to WorkManager and CoroutineWorker for reliability and modern lifecycle handling.