If got some issues with a notification I want to show in the notification bar. Although I set the notification flag to Notification.DEFAULT_LIGHTS & Notification.F
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
From the documentation:
Bit to be bitwise-ored into the flags field that should be set if the notification should be canceled when it is clicked by the user
// Uses the default lighting scheme
notification.defaults |= Notification.DEFAULT_LIGHTS;
// Will show lights and make the notification disappear when the presses it
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
Use the flag Notification.FLAG_AUTO_CANCEL
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
// Cancel the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
and to launch the app:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(context, App.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, intent_id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
While building Notification
by NotificationBuilder
you can use notificationBuilder.setAutoCancel(true);
.
2016 state: you can use mBuilder.setAutoCancel(true)
.
Source: https://developer.android.com/reference/android/app/Notification.Builder.html
The answer for me was to use mBuilder.setOngoing(false)