Firebase(FCM) notifications not coming when android app removed from recent tray
<p>I'm sending Firebase notifications through my own webservice with PHP like below.</p>

<pre><code>$url = 'https://fcm.googleapis.com/fcm/send';
        $fields = array(
             'registration_ids' =&gt; $tokens,
             'data' =&gt; $message
            );
        $headers = array(
            'Authorization:key = SERVER_KEY ',
            'Content-Type: application/json'
            );
</code></pre>

<p>1.Notifications are coming when App is in Foreground and Background without any issues , But if I removed app from recent tray then notifications not coming , I must have to handle this any solution for this ?  (like Whatsup notifications are showing all scenarios even I force stopped this app from settings)</p>

<p>2.Once I received notification , from "onMessageReceived"  how to pass these message,body content to my Activity /Fragments?</p>

<p>3.In some cases I want to send notification to all , Instead of adding all tokens to array . any other way to handle like "send to ALL" something like that ?</p>

<pre><code>public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MsgService";
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Data Payload : " + remoteMessage.getData());
        sendNotification(remoteMessage.getData().get("message"));
    }
    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Firebase Push Notification")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationBuilder.build());
    }
} 
</code></pre>

<p>Failed devices: (Notifications are <strong>not coming</strong> after removed from Recent Tray)</p>

<ul>
<li>MI Redmi Note 2 (5.0.2 Lollipop) </li>
<li>Huawei honor 5c (5.1.1 Lollipop)</li>
</ul>

<p>Succeed devices: (Notifications are coming after removed from Recent Tray)</p>

<ul>
<li>HTC One X (4.2 Jelly Bean)</li>
<li>Samsung galaxy grand prime (4.4 Kitkat)</li>
</ul>