title: Not receiving GCM messages on Android after app is swiped away from recent tasks
body: <p>I am implementing GCM for push notifications using GcmReceiver and GcmListenerService. When the app is running in the foreground or background, I receive the notifications just fine.</p>
  
  <p>My problem is when I swipe the app away from the "recent tasks" list, I can't receive GCM messages anymore (I am on a Xiaomi Mi3). I understand that if you force close an app, you will not receive push notifications anymore. However, swiping it away from the "recent tasks" should still allow the app to receive push notifications. </p>
  
  <p>I have tested this with WeChat and Facebook Messenger, and I do still receive notifications when I swipe the app away (but not if I force close it from Settings).</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.considerdigital.p1mobileapp" &gt;
  
  &lt;permission android:name="com.considerdigital.p1mobileapp.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt;
  &lt;uses-permission android:name="com.considerdigital.p1mobileapp.permission.C2D_MESSAGE" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.SEND" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
  &lt;application
      android:name=".App"
      android:allowBackup="true"
      android:icon="@drawable/p1_app_icon"
      android:label="@string/app_name"
      android:theme="@style/Theme.P1mobileapp" &gt;
  
      &lt;receiver
          android:name="com.google.android.gms.gcm.GcmReceiver"
          android:exported="true"
          android:permission="com.google.android.c2dm.permission.SEND" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;category android:name="com.considerdigital.p1mobileapp" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;service
          android:name=".ListenerService"
          android:exported="false" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>GcmListenerService:</p>
  
  <pre><code>public class ListenerService extends GcmListenerService {
  
  private static final String TAG = "MyGcmListenerService";
  
  public static final String FOREGROUND_NOTIFICATION = "FOREGROUND_NOTIFICATION";
  
  private NotificationManager mNotificationManager;
  
  @Override
  public void onMessageReceived(String from, Bundle data) {
  
      // Send notification only if app is in background
      if (!P1GlobalVariables.getSharedInstance().isAppActive) {
          System.out.println("App is inactive");
  
          sendNotification(data);
      } else {
          System.out.println("App is active");
  
          sendForegroundNotification(data);
      }
  
      Log.i(TAG, "Received: " + data.toString());
  }
  </code></pre>