I want to schedule a notification everytime the user add a note in the database for a specific time. While there are multiple ways to do it using AlarmManager, BroadcastReceiver etc. How can it be done using WorkManager?
On Android, you will need to open Settings. Then choose Sound>Do Not Disturb>Schedules. On this screen, you have several options to set the days and times for Do Not Disturb, choose which apps to apply it to, and set exceptions.
Android WorkManager is a background processing library which is used to execute background tasks which should run in a guaranteed way but not necessarily immediately. With WorkManager we can enqueue our background processing even when the app is not running and the device is rebooted for some reason.
You should also note that WorkManager is part of androidx while JobScheduler is part of old support libraries.
WorkManager
isn't appropriate for work that needs to happen at a particular time.
You should use AlarmManager
, and specifically AlarmManagerCompat.setExactAndAllowWhileIdle(), to get a callback at a specific time.
You can show notification with the help of workmanager. Workmanger can be used for scheduling single occurrence task or periodic occurrence task as well as we can schedule task at a particular time.
OneTimeWorkRequest request= new OneTimeWorkRequest.Builder(CustomWorkerClass.class)
.setInitialDelay(delayedTime, TimeUnit.MILLISECONDS)
.addTag("TAG")
.build();
'delayedTime' -> calculate time when to trigger notification
for more implementation details click here. To read more regarding workmanager click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With