title: How to merge push notifications like whatsapp does in FirebaseMessagingService
body: <p>How to merge push notifications in <strong>FirebaseMessagingService</strong>. I tried almost everything but nothing seems to work. For every new Data object it issues a new notification. The Log where I print number of notifications print 0.<br></p>
  
  <p>Is there any method where I can track if there is any unread notification in notification drawer with the same notificationId, so I can merge the new one with it?<br></p>
  
  <p>Any help will be appreciated.</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  
      private static final String TAG = "MyFirebaseMsgService";
      private static final String actionLiked = "liked";
  mNumber=0;
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
  
             ArrayList&lt;String&gt;notificationString= new ArrayList&lt;&gt;();
  
  
          Log.d(TAG, "From: " + remoteMessage.getFrom());
  
          // Check if message contains a data payload.
          if (remoteMessage.getData().size() &gt; 0) {
              Log.d(TAG, "Message data payload: " + remoteMessage.getData());
              Log.d(TAG, "Number of notifications" +mNumber);
  
              Map&lt;String, String&gt; dataFromCloud =  remoteMessage.getData();
              String action = dataFromCloud.get("action");
              switch (action) {
                  case actionLiked:
                  notificationString.add(action);
                      Intent intent = new Intent(this, MainActivity.class);
                      sendNotification(action, intent);
                      break;
                  default:
                      break;
              }
          }
      }
  
      private void sendNotification(String messageTitle, Intent intent) {
  
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                  PendingIntent.FLAG_ONE_SHOT);
  
                          String[] events = new String[6];
  
  
          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                  .setSmallIcon(R.mipmap.ic_launcher)
                  .setAutoCancel(true)
                  .setContentIntent(pendingIntent)
                  .setNumber(++numMessages);
  
      NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (int i=0; i &lt; notificationString.size(); i++) {
        inboxStyle.addLine(notificationString.get(i));
             }
  
          NotificationManager notificationManager =
                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
          notificationManager.notify(0, notificationBuilder.build());
          }}
  </code></pre>