简体   繁体   中英

Multiple notifications not working on Android

Whenever I receive a push notification on Android it replaces any existing notification in the drawer. any idea to fix that?

Below is my code:

NotificationManager notificationManager = (NotificationManager)
                                getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(DbInsertService.this, MessageActivity.class);
intent.putExtra("Service",serviceType);
PendingIntent pIntent = PendingIntent.getActivity(DbInsertService.this, (int) 
   System.currentTimeMillis(), intent,PendingIntent.FLAG_UPDATE_CURRENT);
 Notification n  = new Notification.Builder(DbInsertService.this)
                                .setContentTitle("Message from " +serviceType.getSer_name())
                                .setContentText(messageType.getHis_title())
                                .setSmallIcon(R.drawable.ic_email_variant_grey600_24dp)
                                .setContentIntent(pIntent)
                                .setAutoCancel(true).build();
                        notificationManager.notify(0, n);

thanks

Set different Id for different notification.

notificationManager.notify(0, n); // here set different Id.

You're sending them all with the same id. Send different ids and they won't overwrite.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM