1
I got this alarm :
This in my acticity Horariosactivity
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 Horariosactivity2
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 Alarm with id 1 that was done in another activity but it fires the same.
then my answer was correct? It would not be enough to work and comment on my reply?
– Mateus