为什么AlarmManager取消不起作用?

时间:2012-11-19 15:04:57

标签: android alarmmanager android-pendingintent android-alarms

您好我正在尝试取消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);

2 个答案:

答案 0 :(得分:0)

尝试将您的旗帜更改为“FLAG_UPDATE_CURRENT”

答案 1 :(得分:-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)