Android notification FLAG_AUTO_CANCEL does not work and does not show new activity

I searched for almost a day for this problem, I followed the example of Android Notification here: http://www.vogella.com/articles/AndroidNotifications/article.html . It worked well and I can send Notification . The problem is that when I click on the notification, it DOES NOT disappear, although I installed:

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 that raised the issue? Thanks for the help.

+4
source share
2 answers

use this.

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

Android notification does not disappear after pressing notifcation button

+5
source

Try to delete:

 noti.flags |= Notification.FLAG_AUTO_CANCEL; 

It should work without noti.flags.

A new way to use flags in NotificationCompat is to use certain methods, such as setAutoCancel (true).

+1
source

Source: https://habr.com/ru/post/1499291/


All Articles