I want to create a notification without canceling/deleting previous notifications from my app. Here is my code for creating a notification:
private void notification(Context context, String title, String content) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(title) .setContentText(content); Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); //Id allows you to update the notification later on. mNotificationManager.notify(100, mBuilder.build()); }
Enable and check notification history on AndroidSwipe up from the homescreen to open the app drawer menu. Find and open the Settings app (it looks like a gear icon). Open Notifications. Select Notification history.
You can see your Android notification history on Android 11 through the Settings app. You first need to turn on Notification history in your phone's notification settings. You will then be able to see all the alerts you dismissed in the past 24 hours.
Pull down the Notification Shade twice, and tap the gear icon under the quick tiles section. Once you're in the Settings app, tap Notifications. In the resulting screen (Figure 1), tap Notifications. Accessing the Notification History in Android 12.
You are using a hardcoded id for your notification, of course it will replace the old one. Try using a variable ID instead of a hardcoded 100.
mNotificationManager.notify(100+x, mBuilder.build());
or something of the sort.
Use variable id for notification, I have faced this issue 1 Hour ago And used this technique to overcome this issue.
val id= Random(System.currentTimeMillis()).nextInt(1000) mNotificationManager?.notify(id, mBuilder.build())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With