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.
Asked
Active
Viewed 352 times
2

Manny265
- 1,709
- 4
- 23
- 42
1 Answers
1
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

Seid
- 56
- 1
- 7
-
the onMessageReceived is not called when app is in background only in foreground,how do u get it called in background? – Manny265 Sep 19 '16 at 21:45
-
you have to send data message instead of notification. Difference between these two types you can find on the link I sent to you in answer. Shortly said you have to rename in json **notification** parameter to **data** – Seid Sep 19 '16 at 21:51
-
wow...this totally sucks,was avoiding implementing server at all cost. thanks though – Manny265 Sep 19 '16 at 22:09