I started to recently face the same issue... But I tried to debug the code and found out that onMessageReceived is never called in my FCM Service class when the app is in the background. This happens when the FCM message payload from the server includes a notification attribute.
Replaced server side code to send a data payload instead of notification and now my onMessageReceived method is always called be the app is in the foreground or background.
More details here -
https://firebase.google.com/docs/cloud-messaging/concept-options
GitHub | FirebaseMessagingService.dispatchMessage
private void dispatchMessage(Intent intent) {
.
.
if (NotificationParams.isNotification(data)) {
.
.
try {
if (displayNotification.handleNotification()) {
// Notification was shown or it was a fake notification, finish
return;
}
}
.
.
}
onMessageReceived(new RemoteMessage(data));
}