Reputation: 161
I am Creating Alarm Application with Setting Alarm of Multiple Days i.e Repeating Alarm.My Android Alarm Application View Like This,
i Have Done Code for this,
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(ALARM_ACTION_NAME);
alarmIntent.putExtra("AlarmID", m_alarmId);
PendingIntent alarmPI = PendingIntent.getBroadcast(this, m_alarmId, alarmIntent, 0);
//listofred is a ArrayList of int items.contains int valye for selected days...for My Example listofred:3,4,5,7
for (int i = 0; i < listOfred.size(); i++) {
// for alarm ...
calNow = Calendar.getInstance();
calSet = (Calendar) calNow.clone();
int day = calSet.get(Calendar.DAY_OF_WEEK); //current day...for example.13 dec 2014 - sat so, day = 7
calSet.set(Calendar.DAY_OF_WEEK, listOfred.get(i));
calSet.set(Calendar.HOUR_OF_DAY, time_picker.getCurrentHour());
calSet.set(Calendar.MINUTE, time_picker.getCurrentMinute());
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calSet.getTimeInMillis(), (DateUtils.DAY_IN_MILLIS)*7,
alarmPI);
//parameter long intervalMillis.....(DateUtils.DAY_IN_MILLIS)*7 so that it will repeat after each 7 days...
}
My Problem is When i run this code it will set repeat alarm for only Saturday(i.e last object in listofred Arraylist) every time it set alarm for last object in Arraylist.
Upvotes: 2
Views: 2955
Reputation: 348
I know it is quite late to answer this, but isn't it because of the same pending intent being passed to each alarm event. Perhaps this might help.
PendingIntent alarmPI = PendingIntent.getBroadcast(this, m_alarmId, alarmIntent, PendingIntent.FLAG_ONE_SHOT);
https://stackoverflow.com/a/3009690/1111127
Upvotes: 1