I am using Firebase Cloud Messaging and I have my own class that extends FirebaseMessagingService
.
My activities order are as follows:
SplashActivity
-> MainActivity
-> DetailsActivity
. When the app is in the MainActivity
and I send a message using the Firebase Console everything is fine it opens up the Dialog
I wanted it to open. Also when I am in MainActivity
and I send a message that is meant to open DetailsActivity
everything is fine.
However when the app is in the background and I send the message, the Notification
does not show as intended and when I click it it opens SplashActivity
first even though the defined Intent
to be opened using PendingIntent
is MainActivity
. How can I go about these two problems?
In my custom FirebaseMessagingService
class I have defined the Intent to have the following flags Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
and my PendingIntent to have the following flags PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT
but it still does not work.
Check if method onMessageReceived in your FirebaseMessagingServise is properly called in background, so you can setup what you need.
I had to send data message type instead of notification, because when you send type notification then method OnMessageReceived is not called in background and firebase handles push notification instead of you. Be aware you cannot even combine type notification and data message.
More about data message you can find here https://firebase.google.com/docs/cloud-messaging/concept-options