AlarmManager does not cancel the scheduled alarm

1

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 ...

    
asked by anonymous 25.01.2015 / 12:26

1 answer

1

I changed the line Intent intent = new Intent(context, MyReceiver.class); to Intent intent = new Intent(context, ReceiverNotification.class);

public void setAlarmCancel(Context context){

        Intent intent = new Intent(context, ReceiverNotification.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!");

    }
    
25.01.2015 / 14:04