Reputation: 41
For eg: I am enqueuing PeriodicWorkRequest of time interval 24 hours with constraints of Network need and Charging. If the constraints are never met within the 24 hours, will the work manager ever doWork as they mentioned in Android dev guide site "fire-and-forget" and "WorkManager is intended for tasks that require a guarantee that the system will run them"
Upvotes: 0
Views: 526
Reputation: 3504
TL;DR WorkManager
gets work done only if all constraints are met.
One of the most usual use-case for constraints would be to communicate with server only when internet connection is available. So it doesn't make sense to run the task at all if connection is not available.
Info from docs (emphasis mine):
WorkManager is a library used to enqueue work that is guaranteed to execute after its constraints are met
source: https://developer.android.com/reference/androidx/work/WorkManager
If you wish, you can specify constraints on when the task should run. For example, you might want to specify that the task should only run when the device is idle, and connected to power.
source: https://developer.android.com/topic/libraries/architecture/workmanager
But just to be 100% sure I tested it on sample code and it confirmed everything above.
Upvotes: 1