title: How to cancel Notification once set?
body: <p>I've set a notification this way:</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
      nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  
      Bundle bundle = intent.getExtras();
  
      CharSequence from = bundle.getString("alarm_title");
      CharSequence message = bundle.getString("alarm_text");
      int notify_id = bundle.getInt("notify_id");
  
      Intent notifyIntent = new Intent(context, AppActivity.class);
      notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  
      PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);
  
      Notification notif = new Notification(R.drawable.ic_menu_glases, "App Information", System.currentTimeMillis());
      notif.contentIntent = contentIntent;
      notif.setLatestEventInfo(context, from, message, contentIntent);
      notif.flags = Notification.FLAG_AUTO_CANCEL;
  
      nm.notify(notify_id, notif);  
  </code></pre>
  
  <p>} </p>
  
  <p>Everything works fine and I'm happy with it. Now I'd like to <code>cancel</code> the notification by ID.</p>
  
  <p>My <strong>1st try</strong> failed (alarm still coming up):</p>
  
  <pre><code>AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  Intent intent = new Intent(getApplication(), AlarmReceiver.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplication(), notifyID, intent, PendingIntent.FLAG_ONE_SHOT);
  if(pendingIntent != null) {
      am.cancel(pendingIntent);
      pendingIntent.cancel();  
  }
  </code></pre>
  
  <p>And <strong>2nd try</strong> failed too:</p>
  
  <pre><code>NotificationManager nm = (NotificationManager) getApplication().getSystemService(Context.NOTIFICATION_SERVICE);
  nm.cancel(notify_id);
  </code></pre>
  
  <p>Anybody got an idea of how to stop the notification once set? Thank you!</p>