I am using Firebase Cloud Messaging on Android.
The problem is in your backend. See this answer. When the message contains notification object, onMessageReceived is called only when the app is foreground. So you have to use only data object. Eg:
var message = {
to: user.deviceId, // required
collapse_key: 'key',
data: {
title: 'Hello',
body: 'Body'
}
};
This works for every scenario.