2011-12-13 121 views
1

我有一个应用程序,允许设置多个闹钟,它每天重复这些闹钟,它工作正常。 我的问题是,当我删除一个设置为在凌晨12:00被解雇的闹钟时,即使它被删除,它也会在12:00 a.m被解雇!任何人都知道问题出在哪里?删除闹钟

我正在使用SQLite来存储,检索和删除警报。

这是AlarmManager我给每一个报警不同的请求的部分代码:

Intent i = new Intent(mContext, Daily_OnAlarmReceiver.class); 
    i.putExtra(RemindersDbAdapter.KEY_ROWID_DAILY, (long)reminderId); 
    int Daily_requestCode = reminderId.intValue(); 

    PendingIntent pi = PendingIntent.getBroadcast(mContext, Daily_requestCode, i, PendingIntent.FLAG_CANCEL_CURRENT); 

    mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi); 

,我也做了通知一样。我给每个通知一个不同的请求代码。

任何人都知道即使我删除它,为什么警报还在发射?

回答

4

呼叫cancel()AlarmManager

Intent intent = new Intent(this, AlarmReceive.class); 
PendingIntent sender = PendingIntent.getBroadcast(this, 
       0, intent, 0); 
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 

alarmManager.cancel(sender); 
+0

感谢您回答我的问题。我尝试过,但这会导致所有的警报不起火。如何仅为已删除的警报调用它? – zoza

0

即使您正在使用不同requestId值,该AlarmManagercancel()方法只检查您指定的PendingIntent相等。但是,根据documentation,过滤器相等性不取决于您的额外数据。所以你必须全部取消它们,然后通过你的数据库循环来添加它们(跳过你正在删除的那个)。