界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
效率与协作 · SKILL.md

android-background-work

android-background-work

【效率与协作】Implement WorkManager and background processing correctly on Android. Use when creating Worker classes, scheduling tasks, choosing between WorkManager and Foreground Services, or setting up Hilt in workers; defer FCM and notification delivery to android-notifications.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: android-background-work description: Implement WorkManager and background processing correctly on Android. Use when creating Worker classes, scheduling tasks, choosing between WorkManager and Foreground Services, or setting up Hilt in workers; defer FCM and notification delivery to android-notifications. metadata: triggers: files: - '**/*Worker.kt' keywords: - CoroutineWorker - WorkManager - doWork - PeriodicWorkRequest - OneTimeWorkRequest - '@HiltWorker'

Android Background Work Standards

Priority: P1 (HIGH)

Implementation Guidelines

WorkManager

  • CoroutineWorker: Use for all background tasks.
  • Constraints: explicit (Require Network, Charging).
  • Hilt: Use @HiltWorker for DI integration. Inject dependencies via @AssistedInject constructor; bind with HiltWorkerFactory in WorkManager configuration.

Foreground Services

  • Only When Necessary: Use generating visible notifications only for tasks user actively aware of (Playback, Calls, Active Navigation). Otherwise use WorkManager.

Anti-Patterns

  • No IntentService: Deprecated. Use WorkManager for all background tasks.
  • No Short Background Jobs: Use Coroutines in ViewModel scope instead.

References

我的收藏