I am making a small app where I have to set alarm from array but only one alarm is set and working at a time which is at last position of array why it is behaving like this following is my code
AlarmManager[] alarmManager=new AlarmManager[24];
for(f=0;f<arr2.length;f++)
{
Intent intent = new Intent(AlarmR.this, Riciving.class);
pi=PendingIntent.getBroadcast(AlarmR.this, 0,intent, 0);
alarmManager[f] = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager[f].set(AlarmManager.RTC_WAKEUP,arr2[f] ,pi);
}
Thanks in Advance
On your
pendingIntentyou need to set the secondrequestCodeto a unique number. I usually run the array through a for loop and set the request code dynamically for each item in the array. Without therequestCodethe alarms are overwriting each other.Basically, you just want to change
requestCodeto a dynamic number. By setting it tofyou are giving it a new unique id for every item in the array. Keep in mind, if you want to cancel the alarms you will need to use another for loop and cancel each one individually. I personally add all my alarms to their own array so I can handle them separately.Then if you need to cancel them: