title: Android Firebase MyFirebaseMessagingService not called when app is swiped from recent list
body: <p><strong>Edit 24/11/2016:</strong>
  I've just received word from Firebase Support. They suggest this is an Asus issue. The device I'm using is an Asus ZenFone 2 Laser. Here's their response:</p>
  
  <blockquote>
    <p>The issue here is that Google does not control how manufacturers
    customize their version of android. If Asus is following the Android
    guidelines, then the notification should work (like on the other
    devices).</p>
    
    <p>One thing that we found is that some phones put the apps in force-stop
    state, which prevents the app from receiving the notification.</p>
    
    <p>From your test result this doesn't seems to be the case. BUT there are
    many other ways in which Asus can stop notifications from working, and
    unfortunately we cannot check all of them.</p>
    
    <p>It would be best for you to contact Asus support and let us know if
    there are any news.</p>
  </blockquote>
  
  <p>As this is a low priority issue for my client, I'm not going to pursue it further at the moment. I unfortunately don't have the time to test the same issue on other devices. If this changes in the future and I'll update this issue accirdingly. Until now, I will consider this unsolved. I would be interested to hear if others are having the same issues on other brand phones.</p>
  
  <p>As for Asus users, there's one thing to consider: There are <a href="http://www.asus.com/zentalk/ph/thread-53927-1-1.html" rel="nofollow noreferrer">power saving settings</a> that disable notificaitons.</p>
  
  <p><strong>Edit 30/09/2016:</strong>
  I've contacted Firebase support about this issue. They seem to agree with what Arthur Thompson is saying:</p>
  
  <ul>
  <li>Stopped apps should not receive messages. </li>
  <li>Swiping an app from the recent list should <strong>not</strong> stop an app.</li>
  </ul>
  
  <p>The interesting part is that my app doesn't seem to be stopped. When running <code>adb shell dumpsys package | grep stopped</code> my package returns:</p>
  
  <pre><code>User 0:  installed=true hidden=false stopped=false notLaunched=false enabled=0
  </code></pre>
  
  <p>This indicates it's not stopped and should still receive messages (according to the very helpful Firebase Support engineer). However the app is not receiving the messages.</p>
  
  <p><strong>Edit 27/09/2016:</strong>
  I've omitted the <code>notification</code> object in the payload and moved that information do the <code>data</code> object instead. This doesn't solve the issue. I think I haven't been clear enough on what the issue is. The issue is that when the app is killed (swiped out of recent) the service doesn't get called or receive notifications anymore.</p>
  
  <p><strong>Original post</strong></p>
  
  <p>There's similar posts out there, but none that address this issue or give a solution. </p>
  
  <p>I'm implementing FCM to get notifications. (I'm fairly new at FCM.) The message payload is a combo of both <code>notification</code> and <code>data</code>. When the app is in the foreground the service fires the <code>onMessageReceived()</code>. When the app is in the background (i.e. I push the home button), <code>onMessageReceived()</code> doesn't fire (as expected) but simply shows a notification. I can still see the log statements on <code>MyFirebaseMessagingService.onCreate()</code> and <code>onDestroy()</code>, which is great.</p>
  
  <p>Now when I close the app by pushing the 'recent apps' button, and swiping the app out of the list, I no longer receive any notifications. <code>onCreate()</code> and <code>onDestroy()</code> are no longer called. No notification appears. I would like a notification to appear in this scenario too.</p>
  
  <p>Example payload:</p>
  
  <pre><code>{
      "to":"token",
      "priority":"high",
      "notification": {
          "body":"hello",
          "title":"Message from Mom",
          "click_action":"ACTIVITY_MAIN"
      },
      "data":{
          "open":"chat"
      }
  }
  </code></pre>
  
  <p>FCM Service:</p>
  
  <pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
  
      @Override
      public void onCreate() {
          super.onCreate();
          Log.v(DmcApplication.TAG, "Service Created");
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          Log.v(DmcApplication.TAG, "Service Destroyed...");
      }
  
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
          Log.v(DmcApplication.TAG, "Message received!");
          EventBus.getDefault().post(new MessageEvent(remoteMessage.getNotification().getBody()));
      }
  
  }
  </code></pre>
  
  <p>Bit of the manifest (in case relevant)</p>
  
  <pre><code>&lt;service
      android:name="com.example.package.myFirebaseMessagingService"
      android:exported="false"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
      &lt;/intent-filter&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p>Logs:</p>
  
  <pre><code>//Log when app is in foreground and message comes in:
  V/coo: Service Created
  V/coo: Message received!
  V/coo: Service Destroyed...
  
  //Log when app is in background and message comes in:
  V/coo: Service Created
  V/coo: Service Destroyed...
  
  //Log when app is killed:
  &lt;silence...&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated as I've been stuck with this for days now.</p>