title: Android: Using AUTO-CANCEL on a notification when your app is running in the background
body: <p>I have looked at all the other AUTO-CANCEL-not-working questions here, and they all seem to involve mistakes that I am not making. I have tried both </p>
  
  <pre><code>builder.setAutoCancel(true);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Notification notif = builder.build();
  notif.flags |= Notification.FLAG_AUTO_CANCEL;
  </code></pre>
  
  <p>Neither works.</p>
  
  <p>I am using NotificationCompat since my minimum API is 8. Here is my full code. In this particular notification, I am not calling an intent, since I don't need the user to do anything.</p>
  
  <pre><code>NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
  builder.setContentTitle(getString(R.string.app_name) + ": my title");
  builder.setContentText(message);
  builder.setSmallIcon(R.drawable.notification_icon);
  
  Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.prog_icon);
  builder.setLargeIcon(bitmap);
  
  builder.setAutoCancel(true); // dismiss notification on user click
  
  NotificationManager notiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  notiManager.notify(MY_NOTI_MANAGER_ID, builder.build());
  </code></pre>
  
  <p>The notification displays just perfectly. You can swipe to clear it. But simply tapping it does not dismiss the notification. It just lights up and stay there.</p>
  
  <p>Some possible differences between my code and others' posted here: 
  1) I am using NotificationCompat (which should not make a difference, but we've heard that before).
  2) Since my notification is simple, I do not attach an intent.</p>
  
  <p>Please let me know if you have any insights.</p>
  
  <p>Edit: My purpose is to dismiss a notification without foregrounding my background app.</p>