5

I've been searching for almost a day for this problem, I followed the example about Android Notification here: http://www.vogella.com/articles/AndroidNotifications/article.html. It worked well and I can send the Notification. The problem is, when I click on the notification, it does NOT disappear even though I have set:

setAutoCancel(true) AND notification.flags |= Notification.FLAG_AUTO_CANCEL

Update: Here is my code

Intent intent = new Intent(MyNotification.this, NotificationReceiver.class);

PendingIntent pIntent = PendingIntent.getActivity(
    MyNotification.this, 0, intent, 0);

NotificationCompat.Builder builder = 
     new NotificationCompat.Builder(MyNotification.this)
    .setSmallIcon(R.drawable.ic_launcher)
    .setAutoCancel(true)
    .addAction(R.drawable.ic_launcher, "Call", pIntent)
    .addAction(R.drawable.ic_launcher, "More", pIntent)
    .addAction(R.drawable.ic_launcher, "And more", pIntent)
    .setContentTitle("New mail from " + "test@gmail.com")
    .setContentText("Subject");

Notification noti = builder.build();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = 
    (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);

Any ideas where the problem come from? Thanks for your helps.

pevik
  • 4,523
  • 3
  • 33
  • 44
user2652394
  • 1,686
  • 1
  • 13
  • 15

2 Answers2

5

Use this:

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

Source: @synic's answer to Android notification doesn't disappear after clicking the notification

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Aarun
  • 564
  • 1
  • 6
  • 13
1

Try removing:

noti.flags |= Notification.FLAG_AUTO_CANCEL;

It should work without noti.flags.

The new way of using flags in NotificationCompat is to use the defined methods, like setAutoCancel(true).

clauziere
  • 1,323
  • 12
  • 20