title: FCM showing duplicate notification when app is in background
body: <p>I implemented FCM in my project. Push notification is working as expected, onMessageReceived is called when a notification is received. This is true when app is in the foreground.</p>
  
  <p>However, when the app is in the background, the system tray always display a duplicate notification when one arrives (e.g. when Notification A is received, system tray display 2 Notification A)</p>
  
  <p>How to fix this?</p>
  
  <p>EDIT: added code</p>
  
  <p>I extended <code>FirebaseMessagingService</code> class and have this in the <code>onMessageReceived</code> method</p>
  
  <p>This is the only part in the project where I used NotificationManager.</p>
  
  <p>Also, I tried to add a log on this method. onMessageReceived is called when app is in foreground. It doesn't get called when app is in background</p>
  
  <pre><code>@Override
  public void onMessageReceived(RemoteMessage remoteMessage)
  {
      RemoteMessage.Notification notification = remoteMessage.getNotification();
  
          Intent intent = new Intent(this, MainActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                  PendingIntent.FLAG_ONE_SHOT);
  
          String title = notification.getTitle();
          String message = notification.getBody();
  
          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                  .setSmallIcon(R.mipmap.ic_launcher)
                  .setContentTitle(title)
                  .setContentText(message)
                  .setAutoCancel(true)
                  .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                  .setContentIntent(pendingIntent);
  
  
          NotificationManager notificationManager =
                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
          notificationManager.notify(0, notificationBuilder.build());
  }
  </code></pre>