onMessageReceived
is called only when the when there is no notification attached to the message.
So for messages with both notification and payload, it won't be called.
According to FCM documentation:
onMessageReceived is provided for most message types, with the following exceptions:
Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.
Messages with both notification and data payload, when received in the background. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
As you can see, onMessageReceived
is called even if your app is in background.