I want to display a notification inside the app that disappears when the notification is tapped without starting an activity.
I use an empty intent and it works:
Intent intent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(context, (int)System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, "")
.setSmallIcon(R.drawable.icon)
.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true)
.setTicker(text);
.setContentIntent(contentIntent);
However, there are some crashes:
java.lang.RuntimeException: bad array lengths
at android.os.Parcel.readIntArray(Parcel.java:789)
at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:339)
at android.app.NotificationManager.notify(NotificationManager.java:139)
at android.app.NotificationManager.notify(NotificationManager.java:112)
...
According to this SO answer the crashes seem to happen because intent
is not starting an activity.
A notification can be dismissed by its ID, but I cannot dismiss it when there is no activity to start and call the dismiss method.
How can I dismiss the notification on tap inside the app without using an empty intent?
Update:
According to this SO questions it seems to be an Android issue. The crashes I got reported also happened on Android 4.3.
Update 2:
According to this SO answer it seems to be due to a too large bitmap set with setLargeIcon
. So I am reducing the bitmap size now with Glide.