FirebaseMessagingService : intent.putExtra() does not work if app is not running
<p><strong>EDIT3:</strong> Ok I found the problem : If the app is killed, sending both <code>data</code> <strong>and</strong> <code>notification</code> won't trigger <code>onMessageReceived</code>. <code>notification</code> needs to be set to null if the target device is android.</p>

<p>That's really a dumb behaviour.</p>

<p><strong>Original post:</strong></p>

<p>I can successfully retrieve the bundle from the intent passed by the <code>notificationBuilder</code> to the activity when the app is launched.</p>

<p>However, if I kill the app, the notification still works but the <code>GetExtras()</code> from the intent is null.</p>

<p>In my <code>FirebaseMessagingService</code> child class:</p>

<pre><code>@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
     Intent intent  = new Intent(this, MainActivity.class);        
     intent.putExtra("key_1","value");
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    //also tried with  PendingIntent.FLAG_CANCEL_CURRENT


     Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("title")
            .setContentText("messageBody")
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());

}
</code></pre>

<p>When the app is killed, the <code>firebaseMessagingService</code> can't even write a file. It does not crash, it builds, and shows the notification, but anything done to the disk does not work.</p>

<p><strong>EDIT:</strong> I have replaced the content of the <code>onMessageReceived</code> method as follows:</p>

<pre><code>@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
     // Do nothing
}
</code></pre>

<p>When the app is running nothing happens -as expected- but when the app is killed a notification is displayed whith the name app as a title and <code>remoteMessage.getNotification().getBody()</code> as content text.</p>

<p>It seems that <code>onMessageReceived</code> is not fired. Instead another magic function is called...</p>

<p><strong>EDIT2:</strong> As requested, this is what is sent from the server:</p>

<pre><code>{
    "data":
     {
          "form_id":"33882606580812",
          "recipientUserId":10500
     }
     ,
     "to":"e0bU2jIVO9g:APA91bHsS-s3G1gQLcTFtRUC77pJUWcZvD7h9NfUgFLD-bFam1S0dddngVcmrQlXR5i6DfTsc69T8JbIrSuzyF1iv0c4ac1gmkwvGVMwZo_yA4KwOh82Nx-weYeL79r79si4qH3QBEgs",
     "notification":
     {
          "body":"you have a new notification",
          "badge":"1",
          "sound":"default"
     },
     "delay_while_idle":false
}
</code></pre>