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
Android Fragment Onrestoreinstancestate
How to Iterate Through a View's Elements
Cursorloader Not Updating After Data Change
How to Use the Android Accelerometer
Calculate the Size of a List View or How to Tell It to Fully Expand
Create Custom Big Notifications
How to Use Isineditmode() to See Layout with Custom View in the Editor
How to Iterate Through All Keys of Shared Preferences
Menu Items Are Not Showing on Action Bar
Android Broadcastreceiver Within Activity
Ontouchevent Not Working on Child Views
How to Capture Image from Custom Cameraview in Android
Display Huge Images in Android
Login Error: There Is an Error in Logging You into This Application. Please Try Again Later
How to Use Android Emulator for Testing Bluetooth Application