I have the following code in MyReceiver
:
@Override
public void onReceive(Context context, Intent intent){
context.startService(new Intent(context, BackgroundService.class));
}
public void setAlarm(Context context, long mills){
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, ReceiverNotification.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 2310, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, (mills + 60000), 120000, pi);
}
public void setAlarmCancel(Context context){
Intent intent = new Intent(context, MyReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 2310, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
Log.v(TAG, "Alarme cancelado!");
}
And I have this for notifications:
public class ReceiverNotification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent){
context.startService(new Intent(context, NotificationService.class));
}
}
When I call for a certain time, calling the method setAlarmCancel()
, I get the LOG return but the alarm continues. Thanks for your help ...