title: How to clear notification on android when clicked
body: <p>Every time I click on notification the activity pops on screen which I had used to trigger the notification in the status window.</p>
  
  <p>I want to clear the notification when a user clicks on it, but it opens the activity every time.</p>
  
  <p>I tried using flags not only on notification but on PendingIntent and Intents too.</p>
  
  <p>My code:</p>
  
  <pre><code>NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
  Notification not = new Notification(R.drawable.ic_launcher,
          "this is not important", System.currentTimeMillis());
  
  Context context = MainActivity.this;
  
  CharSequence title = "You have been notified";
  CharSequence  details = "contiue with work";
  
  not.flags =  Notification.FLAG_AUTO_CANCEL;
  
  Intent intent = new Intent(context, MainActivity.class);
  PendingIntent pending = PendingIntent.getActivity(context, 0, intent, PendingIntent. FLAG_ONE_SHOT);
  
  not.setLatestEventInfo(context, title, details, pending);
  nm.notify(0, not);
  </code></pre>
  
  <p>and also:</p>
  
  <pre><code>PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>PendingIntent pending = PendingIntent.getActivity(context, 0, intent, Notification.FLAG_AUTO_CANCEL);
  </code></pre>
  
  <p>Every time I click on notification activity comes on the screen, I just want to clear notification.</p>
  
  <p>Here is Logcat</p>
  
  <pre><code>09-01 00:21:10.910: E/AndroidRuntime(330): FATAL EXCEPTION: main
  09-01 00:21:10.910: E/AndroidRuntime(330): java.lang.IllegalArgumentException: contentIntent required: pkg=nipun.notify id=0 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x10)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.os.Parcel.readException(Parcel.java:1326)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.os.Parcel.readException(Parcel.java:1276)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.app.NotificationManager.notify(NotificationManager.java:111)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.app.NotificationManager.notify(NotificationManager.java:91)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at nipun.notify.MainActivity$1.onClick(MainActivity.java:49)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.view.View.performClick(View.java:2485)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.view.View$PerformClick.run(View.java:9080)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.os.Handler.handleCallback(Handler.java:587)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.os.Handler.dispatchMessage(Handler.java:92)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.os.Looper.loop(Looper.java:123)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at android.app.ActivityThread.main(ActivityThread.java:3683)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at java.lang.reflect.Method.invokeNative(Native Method)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at java.lang.reflect.Method.invoke(Method.java:507)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  09-01 00:21:10.910: E/AndroidRuntime(330):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>