I'm trying to implement an Android app that needs to alarm (or to alert) multiple times along the time.
I've already searched, but the nearest I found was a fixed-number of alarms set, and I guess the example didn't work.
What I want to know if there is exists an approach to dynamically set multiple alarms, like an Array of alarms and then to trigger those alarms in their specific timestamps.
You can set the repetition of the alarm:
in this case:
To dynamically set up multiple alarms, the approach which I used is that I created a single alarm. Then in my alarm setting class, a static integer (to be used as requestcode) is initialized which will be incremented each time from my main activity whenever I click on "add alarm" button in my main activity. E.g.
MainActivity.java
AlarmActivity.java
I hope this will help.
If you want to set multiple alarms (repeating or single), then you just need to create their
PendingIntent
s with differentrequestCode
. IfrequestCode
is the same, then the new alarm will overwrite the old one.Here is the code to create multiple single alarms and keep them in
ArrayList
. I keepPendingIntent
's in the array because that's what you need to cancel your alarm.Also, see this question: How to set more than one alarms at a time in android?.