if you are canceling previous alarms then in PendingIntent
your flag should be PendingIntent.FLAG_CANCEL_CURRENT
. It will prevent generating a new PendingIntent
if it is already created. And make sure that before setting in alarm just cancel that same PendingIntent
and after that set your alarm. You should try like this:
AlarmManager 2AlarmsInWeekAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService/getActivity(context, int, intent, PendingIntent.FLAG_CANCEL_CURRENT);
2AlarmsInWeekAlarmManager.cancel(pendingIntent);
and then you may use set or setRepeating
method.
In your case it should be
2AlarmsInWeekAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, "timeInMillis", "repetitionTimeInMillis", pendingintent);
This guarantees that before setting an alarm will cancel all previously alarm with the same PendingIntent
.
Hope you got this!