0

嗨,我正在尝试取消 AlarmManager。我写了一些测试代码,但它不起作用,我的代码:

警报创建:

            Intent myIntent = new Intent(this,NotificationService.class);
            PendingIntent pendingIntentFriday = PendingIntent.getService(this,123098,myIntent, PendingIntent.FLAG_CANCEL_CURRENT);

            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);         
            alarmManager.set(AlarmManager.RTC_WAKEUP,nextFriday.getTimeInMillis() , pendingIntentFriday);

报警取消:

            Intent stopIntent = new Intent(this,NotificationService.class);
            PendingIntent stopFriday = PendingIntent.getService(this,123098,stopIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            AlarmManager stopManager = (AlarmManager) getSystemService(ALARM_SERVICE);
            stopManager.cancel(stopFriday);
4

2 回答 2

0

尝试将您的标志更改为“FLAG_UPDATE_CURRENT”

于 2013-12-06T15:08:25.787 回答
-3
 AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
 Intent intent = new Intent(context, ReceiverForCancelling.class);
  PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent,
  PendingIntent.FLAG_CANCEL_CURRENT);
   service.cancel(pending)
于 2012-11-20T09:22:56.327 回答