Does the Work manager will stop the work after the constraints become not satisfied while the work is processing. For example, work requires charger connected constraint, after connecting the charger the work starts, and then the charger gets disconnected, does the Work manager will stop the work, as it's not satisfying the constraints anymore
If a constraints is not satisfied anymore during the execution of a worker, WorkManager will signal its stoppage.
Keep in mind that stoppages are cooperative in WorkManager, so your Worker will need to implement the onStopped()
callback and it can use the isStopped()
method while executing long running loops/computation.
From the doc:
You should cooperatively abort any work you had in progress and release any resources your Worker is holding onto. For example, you should close open handles to databases and files at this point. There are two mechanisms at your disposal to understand when your Worker is stopping.
Alsoi from the doc:
Note: WorkManager ignores the Result set by a Worker that has received the onStop signal, because the Worker is already considered stopped.
If you are using CoroutineWorkers, these are going to handle stoppages automatically in the defined scope. From WorkManager's threading guide:
CoroutineWorkers handle stoppages automatically by cancelling the coroutine and propagating the cancellation signals. You don't need to do anything special to handle work stoppages.