What is the easiest way to send notifications on a specific date in Java? I don't need to just send one - I have a list where I can add items and give them a specific date and time. So all of the items have a separate time that I need a notification to be sent out on.
Later on I might also need to be able to stop a notification from going out if I delete an item from the list or have a notification's date be changed if I change the date of the according item in the list. But first I just need to get the notification part working.
CodePudding user response:
The best bet for this is Firebase Cloud Messaging . The reason is that you can control when and what to send via a dashboard in your Firebase Console.
If you want to do it without a system like Firebase you would need a custom backend implementation.
Medium Article on Implementing Firebase Cloud Messaging Push Notifications
CodePudding user response:
ScheduledExecutorService
The Executors framework can execute a task after a certain amount of time elapses. Use ScheduledExecutorService class.
ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor() ;
Be sure to eventually shut down your executor service. Otherwise its backing pool of threads may continue running indefinitely, like a zombie
