WorkManager vs AlarmManager, what to use depending on the case

Should I use AlarmManager directly for this ?

Yes you should. AlarmManager is the best option as far as I know to handle tasks like yours and also is the safer option when dealing with doze mode. Use the first alarm to set the second alarm at a specific time.

Should I use WorkManager to get the time when I need to alarm and than use AlarmManager ?

If you want to use this approach you need to call AlarmManager and dispatch a Worker on WorkManager. The WorkManager need to run before a specific time and is not guaranteed that the Worker finish or will be executed before 4.30.

The reason why I am confused is because some blogs I have read say that is better to stick to AlarmManager if I have some work at a specific time, but still, I can do it with WorkManager

WorkManager doesn’t guarantee the time of execution. It probably can do this in the future.

Should I just use WorkManager ?

No, for the reasons expressed before.
Android-Job is the short term response of your use case if you wanna use a job scheduler. Also you can see a table of features and differences if you go to the link.

Edit 17/03/2020:
Android-Job is deprecated.

Edit 29/03/2023:
For other use cases check the paragraph Acceptable use cases for exemption on documentation.

Leave a Comment