0

嗨我想取消AlarmManager。我写了一些测试代码,但它不是工作,我的代码:为什么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); 
+1

http://stackoverflow.com/a/12119147/726863 –

回答

-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) 
+2

其中是你的代码的解释? –

0

试着改变你的标志,以 “FLAG_UPDATE_CURRENT”