How to Schedule Notifications Using Workmanager

How to schedule notifications using WorkManager?

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.

I want to schedule notification on specific date should i use workmanager?

WorkManager is intended for tasks that are deferrable - that is, not required to run immediately and required to run reliably even if the app exits or the device restarts. For example:

  • Sending logs or analytics to backend services
  • Periodically syncing application data with a server

Alarms (based on the AlarmManager class) give you a way to perform time-based operations outside the lifetime of your application. For example, you could use an alarm to initiate a long-running operation, such as starting a service once a day to download a weather forecast.

Alarms have these characteristics:

  • They let you fire Intents at set times and/or intervals.
  • They operate outside of your application, so you can use them to
    trigger events or actions even when your app is not running, and even
    if the device itself is asleep.

So for your requirement, you should be using an AlarmManager instead of WorkManager as you only need to deliver a notification.

Using Android WorkManager for local Notification instead of AlarmManager

Now I have one option to use WorkerManager,but I have no idea of how to set the time as done in AlarmManager

WorkManager does not support your scenario, sorry.

I cannot use setAndAllowWhileIdle because I need to repeat the notification message.

You can manually repeat by calling setAndAllowWhileIdle() to schedule the next alarm as part of processing the PendingIntent for your last alarm.



Related Topics



Leave a reply



Submit