Reputation: 3407
So I know WorkManager
utilizes JobScheduler
on supported APIs but there doesnt seem to be any way to make WorkManager
work persistent across reboots? Is the only option to request the BOOT_COMPLETED
permission and reschedule jobs?
Upvotes: 1
Views: 2136
Reputation: 6476
To answer your question: You don't need to do anything if the device is rebooted. WorkManager keeps scheduling your Work without any additional requirement from your side.
WorkManager persists Work requests in its internal Room database. This allows it to guarantee Work execution across device restart.
The documentation covers this as this blog "Introducing WorkManager" that the team wrote last year.
Upvotes: 3
Reputation: 3767
WorkManager is actually used to persist deferrable tasks even after your app exits and the device restarts, please refer to the docs. It uses JobScheduler for api 23 and above and broadcastReceiver and AlarmManger on api 14 to 22. You can use constraints to check battery status, network coverage ...etc depending your particular usecase. You just have to be careful not to remove or rename your existing classes after they are added in the queue because WorkManager uses it's internal database to store those classes and your app will crash if you remove them or rename them.
Upvotes: 1