Les applications Android doivent souvent effectuer du travail en arrière-plan — des tâches qui s'exécutent en dehors de l'interface utilisateur immédiate, comme la synchronisation de données, les téléchargements ou les tâches périodiques. Android fournit plusieurs mécanismes (WorkManager, Services, coroutines) avec différents cas d'usage, plus des contraintes importantes du système d'exploitation.
Options de travail en arrière-plan
COROUTINES (in a ViewModel scope) → for async work tied to the UI/screen (network calls,
loading data) — runs while the screen is active
WORKMANAGER → for DEFERRABLE, GUARANTEED background work that must complete (even if the
app closes or the device reboots): syncing, uploads, periodic tasks, retries
→ the RECOMMENDED solution for most persistent background work
FOREGROUND SERVICE → for ongoing, user-visible background work (music playback, navigation,
active tracking) — shows a persistent notification
SERVICES → general background components (largely superseded by WorkManager/coroutines
for most cases)
