I am creating a scheduler application. In that I am setting multiple events using AlarmManager
and PendingIntent
's. I use following methods:
Here I declare PendingIntent
array:
public static ArrayList <PendingIntent> intentArray= new ArrayList <PendingIntent>();
Here I am adding intents to the array:
PendingIntent pendingIntent = PendingIntent.getBroadcast(
EditScheduleActivity.this, intentid, notifyintent,
PendingIntent.FLAG_UPDATE_CURRENT); //intent id is unique
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
pendingIntent);
MainActivity.intentArray.add(pendingIntent);
Here I am clearing an alarm:
EditScheduleActivity.alarmManager.cancel(intentArray.get(selecteditemid_int));
intentArray.remove(selecteditemid_int);
But when I clear an alarm, I am getting an ArrayIndexOutOfBoundsException
,I think the problem is when I restart application, intent array list gets re-initialized and throws exception. How can I overcome this problem by keeping the intent array list not to re-initialized?