I need to set a repeating alarm that will once fired, launch a notification.
Steps:
- I have an interface that takes some date details (Just had a thought, maybe I should be launching an intent to display the “set alarm” feature). The product of the details is a date time string that needs to be fed into an alarm method.
- When setting an alarm I need to create a reference to it so it can be deleted by the user. (Or maybe not, what is best practice? Maybe users can only delete an alarm from the “alarm” section)
- When the alarm goes off a notification will be created.
I’m uncertain of how the alarm system works. The alarm probaly should be silent, maybe with vibration. Is that straight forward to setup?
Do I need a service or will a broadcast reciever do the job?
Basically I just need a few pointers. Am I thinking about this correctly? Is there a tutorial out there (I haven’t found anything). Thanks in advance.
Here is a walkthrough on how I use an AlarmService in my app.
Set up an AlarmManager to fire in x minutes.
In response to the alarm, start a service.
Create your notification and have your service set itself up with a new Alarm to fire again in another x minutes.
The service shuts itself down.
1.
2.
3.
4.(In the Same Class)
Hope this helps!
EDIT
Why use a Service?
It’s not wise to do much processing in the BroadcastReceiver. Although you can do some processing in the BroadcastReciever, it is safer to do this in a Service, you can find some information in this StackOverflow question BroadcastReceiver vs Service