Push notification works incorrectly when app is on background or not running
<p>I am using Firebase Cloud Messaging to send push notifications.</p>

<p>Here is my <code>FirebaseMessageService</code>:</p>

<pre><code>public class FireBaseMessageService extends FirebaseMessagingService {


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e("TAG", "From: " + remoteMessage.getFrom());
    Log.e("TAG", "Notification Message Body: " + remoteMessage.getData().get("CardName")+"  :  "+remoteMessage.getData().get("CardCode"));
    sendNotification(remoteMessage.getNotification().getBody());
}


private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, StartActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher_final)
            .setContentTitle("Notification")
            .setContentText(messageBody)
            .setTicker("Test")
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }
}
</code></pre>

<p>And <code>FirebaseInstanceServer</code>:</p>

<pre><code>public class FirebaseInstanceService extends FirebaseInstanceIdService {


@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.e("TAG", "Refreshed token: " + refreshedToken);

    // TODO: Implement this method to send any registration to your app's servers.
    sendRegistrationToServer(refreshedToken);

}

private void sendRegistrationToServer(String token) {


      // Add custom implementation, as needed.
        Log.e("TAG", "Refreshed token2: " + token);
    }
}
</code></pre>

<p>Which is declared in the <code>AndroidManifest</code>:</p>

<pre><code>&lt;service
    android:name=".util.notifications.FireBaseMessageService"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="com.google.firebase.MESSAGING_EVENT"/&gt;
    &lt;/intent-filter&gt;
&lt;/service&gt;

&lt;service
    android:name=".util.notifications.FirebaseInstanceService"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT"/&gt;
    &lt;/intent-filter&gt;
&lt;/service&gt;
</code></pre>

<p>So issue is that when App is running <code>ticker</code> is shown well and notification come with default sound, but when App is in background or is not running, notification come without any sound and <code>ticker</code> is not shown in status bar.<br>
Why is this happening and how can I fix it?</p>