title: Android: can't cancel AlarmManager
body: <p>I can't seem to be able to cancel my alarm. I have looked at other posts on Stack Overflow but none of them have worked for me.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>AddAlarm class:</strong></p>
  
  <pre><code>public void setAlarm(){
      AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      Intent i = new Intent(AddAlarm.this, AlarmReceiver.class);
      PendingIntent pi = PendingIntent.getBroadcast(AddAlarm.this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
  
      calAlarm = Calendar.getInstance();
      Calendar calNow = Calendar.getInstance();
      Date date = new Date();
  
      calNow.setTime(date);
      calAlarm.setTime(date);
      calAlarm.set(Calendar.HOUR_OF_DAY, pickHour);
      calAlarm.set(Calendar.MINUTE, pickMinute);
      calAlarm.set(Calendar.SECOND, 0);
  
      if (calAlarm.before(calNow) || calAlarm == calNow){
          calAlarm.add(Calendar.DATE, 1);
      }
  
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
          am.setExact(AlarmManager.RTC_WAKEUP, calAlarm.getTimeInMillis(), pi);
      } else {
          am.set(AlarmManager.RTC_WAKEUP, calAlarm.getTimeInMillis(), pi);
      }
  }
  
  public void cancelAlarm(){
      AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      Intent i = new Intent(AddAlarm.this, AlarmReceiver.class);
      PendingIntent pi = PendingIntent.getBroadcast(AddAlarm.this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
  
      am.cancel(pi);
  }
  </code></pre>
  
  <p>Do you guys have any suggestions? Thanks!</p>