I have this alarm:
This in my acticity ScheduleActivity
PendingIntent alarmIntent;
Intent intent = new Intent(HorariosActivity.this, AlarmReceiver.class);
intent.putExtra("agoa", "teste");
alarmIntent = PendingIntent.getBroadcast(HorariosActivity.this, 1, intent, 0);
Calendar calendar = Calendar.getInstance();
long agora = calendar.getTimeInMillis();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 5);
calendar.set(Calendar.SECOND, 22);
firstTime = calendar.getTimeInMillis();
if (agora>firstTime) {
calendar.add(Calendar.DAY_OF_MONTH, 1 );
firstTime = calendar.getTimeInMillis();
}
AlarmManager am = (AlarmManager)HorariosActivity.this.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, 86400000, alarmIntent);
}
In another activity I tried to cancel with this code:
The name of this activity is ScheduleActivity2
PendingIntent alarmIntent;
Intent intent = new Intent(HorariosActivity2.this , AlarmReceiver.class);
HorariosActivity.context = getApplicationContext();
alarmIntent = PendingIntent.getBroadcast(HorariosActivity.context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)HorariosActivity2.this.getSystemService(Context.ALARM_SERVICE);
am.cancel(alarmIntent);
I'm trying to cancel the alarm with id 1 that was done in another activity but it triggers it.