Search code examples
javaandroidkotlinandroid-workmanager

WorkManager stopped status


I have a WorkManager that I use to sync my data. I'm sending both a PeriodicWorkRequest and a OneTimeWorkRequest to Worker. But when I send OneTimeWorkRequest, the status of SystemJobService appears to be stopped. This way work manager works fine but I don't know if it's correct to show as stopped.

Background Task Inspector looks like this enter image description here


Solution

  • OneTimeWorkRequest and PeriodicWorkRequest have different state logic.

    As you saw, once a OneTimeWorkRequest is completed with a Success, Failure or Cancellation. It is marked as stopped.

    WorkManager's documentation covers this topic.

    For PeriodicWorkRequest, the only way to stop it, is a Cancellation. A Success or Failuire, simply re-enqueue the WorkRequest.