title: Android Canceling Alarm Manager - Not Working
body: <p>Alright. I am working on an app where users can schedule times to mute there phones, vibrate there phones, ect...</p>
  
  <p>The app looks good and functions properly, all the way until we get the canceling alarms part of the code.</p>
  
  <p>Here is how I am trying to cancel the alarms.... but it's not working.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> public static void DeleteSpecificAlarm(Context context, int alarmType, int id){
          AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  
          Intent updateServiceIntent;
          switch(alarmType){
              case 0:
                  updateServiceIntent = new Intent(context, MuteAlarmReciever.class);
                  break;
              case 1:
                  updateServiceIntent = new Intent(context, VibrateAlarmReciever.class);
                  break;
              case 2:
                  updateServiceIntent = new Intent(context, CustomAlarmReciever.class);
                  break;
              default:
                  updateServiceIntent = new Intent(context, MuteAlarmReciever.class);
                  break;
          }
          PendingIntent pendingUpdateIntent = PendingIntent.getService(context, id, updateServiceIntent, 0);
  
          // Cancel alarms
          try {
              alarmManager.cancel(pendingUpdateIntent);
              Toast.makeText(context, "Alarm Removed", Toast.LENGTH_LONG).show();
          } catch (Exception e) {
              Log.e("Manager", "AlarmManager update was not canceled. " + e.toString());
              Toast.makeText(context, "AlarmManager update was not canceled!", Toast.LENGTH_LONG).show();
          }
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Request: "Include code of your alarm creation."</p>
  
  <p>Here is how I am creating the alarms:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public static void saveNewData(final Context context, final int volumeType, final int volumeLevel, final TimePicker timePicker){
          ParseQuery query = new ParseQuery("Schedule");
          query.fromLocalDatastore();
          query.findInBackground(new FindCallback&lt;ParseObject&gt;() {
              @Override
              public void done(List&lt;ParseObject&gt; objects, ParseException e) {
                  if(e == null){
                      final int alarmID = objects.size() + 1;
                      ParseObject scheduledItem = new ParseObject("Schedule");
                      scheduledItem.put("volumeType", volumeType);
                      scheduledItem.put("volumeLevel", volumeLevel);
                      scheduledItem.put("alarmID", alarmID);
                      int hour;
                      int minute;
                      if(Build.VERSION.SDK_INT &gt;= 23){
                          hour =  timePicker.getHour();
                          minute = timePicker.getMinute();
                      } else {
                          hour =  timePicker.getCurrentHour();
                          minute = timePicker.getCurrentMinute();
  
                      }
                      scheduledItem.put("hour", hour);
                      scheduledItem.put("minute", minute);
  
                      final Calendar calendar = Calendar.getInstance(); //Full Current Time
                      calendar.set(Calendar.HOUR_OF_DAY, hour);
                      calendar.set(Calendar.MINUTE, minute);
                      calendar.set(Calendar.SECOND, 0);
                      Log.i("SchedRinger", "User saved new time. User's selected time was: " + calendar.getTime().toString() + "\n" +
                              "Reciever ID: " + alarmID + "\n" +
                              "Alarm Type: " + volumeType + "\n" +
                              "Volume Level: " + volumeLevel + " (Irrelevent if Alarm Type != 2)");
  
                      if(hour &gt; 12){
                          if(minute &lt; 10)
                              scheduledItem.put("time",  hour - 12 + ":0" + minute + " PM");
                          else
                              scheduledItem.put("time",  hour - 12 + ":" + minute + " PM");
                      } else {
                          if(minute &lt; 10)
                              scheduledItem.put("time",  hour + ":0" + minute + " PM");
                          else
                              scheduledItem.put("time",  hour + ":" + minute + " PM");
                      }
  
                      scheduledItem.pinInBackground(new SaveCallback() {
                          @Override
                          public void done(ParseException e) {
                              if(e == null){
                                  Toast.makeText(context, "Saved.", Toast.LENGTH_LONG).show();
                                  ScheduleSpecificAlarm(context, calendar, volumeType, volumeLevel, alarmID);
                              } else {
                                  Toast.makeText(context, "Failed to save. " + e.getMessage(), Toast.LENGTH_LONG).show();
                              }
                          }
                      });
                  } else {
                      //TODO: Error
                  }
              }
          });
  
  
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>private static void ScheduleSpecificAlarm(Context context, Calendar cal, int alarmType, int volumeLevel, int id){
  
          Intent intentAlarm;
  
          switch (alarmType){
              case 0:
                  intentAlarm = new Intent(context, MuteAlarmReciever.class);
                  break;
              case 1:
                  intentAlarm = new Intent(context, VibrateAlarmReciever.class);
                  break;
              case 2:
                  intentAlarm = new Intent(context, CustomAlarmReciever.class);
                  intentAlarm.putExtra("volumeLevel", volumeLevel);
                  break;
              default:
                  intentAlarm = new Intent(context, MuteAlarmReciever.class);
                  Toast.makeText(context, "Error. Variable passed in wrong on Alarm Creation. Defaulted to 'mute' alarm", Toast.LENGTH_LONG).show();
                  break;
          }
  
          AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  
          PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intentAlarm, 0);
  
          alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY, pendingIntent);
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Im saving with Parse.com. Which if you do not know the API, just know that you can store and save data in ParseObjects. It's like the Prefs system android hasm but I don't have to worry about sending it via intent.</p>
  
  <p>The Catch Statement is <strong>not</strong> thrown. Why isn't it working? Any ideas?</p>