1

I have an application that allow multiple alarms to be set and it repeats those alarms every day and it is working fine. My problem is when I delete an alarm that was set to be fired at 12:00 a.m. the next day it will be fired at 12:00 a.m even if it is deleted! Anyone know where the problem might be?

I'm using an SQLite to store, retrieve and delete the alarms.

This is part of the AlarmManager I'm giving every alarm a different request code:

 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);

and I'm also doing the same way for the notification. I'm giving every notification a different request code.

Anyone know why the alarm is firing even if I delete it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
zoza
  • 127
  • 3
  • 12

1 Answers1

0

Even though you are using different requestId value, the AlarmManager cancel() method only checks the PendingIntent that you specify is equal. However, filter equality does not depend on your extra data according to documentation. So you have to cancel them all and then loop through your database to add them back (skipping the one(s) you are deleting).

davidcesarino
  • 16,160
  • 16
  • 68
  • 109
mevun
  • 431
  • 1
  • 5
  • 9