title: Firebase cloud messaging not received when app in background
body: <p>I recently updated my app to send messages through <strong>FCM</strong> and it works great when the app is run on Jelly Bean. The problem is it doesn't in case it's <strong>Lollipop</strong> and the app is in the <strong>background</strong>.</p>
  
  <p>I read the <a href="https://firebase.google.com/docs/cloud-messaging/concept-options#data_messages" rel="nofollow noreferrer">documentation</a> and it's stated that when the payload is a data message, it will be handled by <em>onMessageReceived()</em>. I am sending a data payload, <strong>not a notification</strong>, and it's handled correctly as long as it's JellyBean. For Lollipop it only handles the message if the app is in the foreground. If not, nothing happens.</p>
  
  <p>This is how the beginning of my FirebaseMessagingService looks like:</p>
  
  <pre><code>public class FirebaseBroadcastReceiverService extends FirebaseMessagingService {
      private final String TAG = FirebaseBroadcastReceiverService.class.getName();
  
      @Override
      public void onMessageReceived(RemoteMessage message){
          Log.i(TAG, "A message is received");
          String from = message.getFrom();
          Map&lt;String, String&gt; data = message.getData();
          .....
      }
  }
  </code></pre>
  
  <p>The manifest:</p>
  
  <pre><code>&lt;application
      android:name=".controller.application.AppResources"
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher_shadow"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@android:style/Theme.Black.NoTitleBar"&gt;
  
     &lt;service
          android:name=".model.firebase.FirebaseListenerService"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
      &lt;service android:name=".model.firebase.FirebaseBroadcastReceiverService"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
      .......
  &lt;/application&gt;
  </code></pre>
  
  <p>And the payload:</p>
  
  <pre><code>{ 
      "data": {
          "test": "test"
      },
      "to" : "MY FCM REGISTRATION ID"
  }
  </code></pre>
  
  <p>Which is sent via POST to <em><a href="https://fcm.googleapis.com/fcm/send" rel="nofollow noreferrer">https://fcm.googleapis.com/fcm/send</a></em> with the Authorization and Content-type headers.</p>
  
  <p>I might have read all other SO threads related to this but I couldn't find an answer to it and there are also no log traces in the Android Monitor. Does anyone have a hint on this?</p>