1

This is what sets the alarm

    public void setSilent(Long taskId, Calendar when){
     Intent i = new Intent(mContext, SilentReceiver.class);
     PendingIntent pi = PendingIntent.getBroadcast(mContext, 1 , i, PendingIntent.FLAG_ONE_SHOT);
     mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);

It takes in an id and date to use with the intent. I am canceling it in another file when the user clicks delete. using

Intent i = new Intent(null, SilentReceiver.class);
         PendingIntent pi = PendingIntent.getBroadcast(null, 1 , i, PendingIntent.FLAG_ONE_SHOT);

should this work because it has the same request code as the first one or am I doing something wrong?

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Bob
  • 11
  • 2
  • 1
    Just curious, why is the first parameter to Intent null ? Also, take a look at this: http://stackoverflow.com/questions/3330522/how-to-cancel-this-repeating-alarm – advantej Apr 26 '11 at 01:07
  • check your PendingIntent [exists or not](http://stackoverflow.com/q/4556670/1342413) – laplasz Feb 26 '13 at 15:37

2 Answers2

1

You have to save a reference to your first PendingIntent. This way you can use:

mAlarmManager.cancel(pi);

And the alarm should be cancelled.

This answer has been repeated many times. Please search before asking.

Vicente Plata
  • 3,360
  • 1
  • 18
  • 26
0

Be careful to send a PendingIntent to stop the alarm with the same data than the Intent to create the alarm: problem with cancel the alarm manager pending intent

Community
  • 1
  • 1
noloman
  • 10,696
  • 17
  • 80
  • 118