0

I'm using firebase cloud messaging. I have implemented FirebaseMessagingService. And everything seems to be working well. However, I have a question, is it possible, if my application is not running, that the method onMessageReceived will not be called and the notification data will be received in the Intent of my launch activity ?

I tried to test, and when my application is in the background or not running at all, in any case, the onMessageReceived is called.

However, I have seen code examples where push notification data is received in the launch activity inside onCreate via Intent, how can they get there if the onMessageReceived is not called?

Please, help me.

Note: I know that it is possible to start my activity inside the onMessageReceived using the pending intent, and pass information there with a push notification, but I'm talking about cases where the onMessageReceived may not be called. Perhaps the firebase SDK has its own mechanisms by which it can transfer information from the notification to the Intent of launch activity?

testivanivan
  • 967
  • 13
  • 36
  • "I have seen code examples where push notification data is received in the launch activity inside onCreate via Intent" - please share these examples. – dominicoder Mar 21 '23 at 15:15
  • @dominicoder, unfortunately I can't share, these are commercial projects – testivanivan Mar 21 '23 at 21:31
  • You should be able to share a trivial, minimal example that shows what you mean without giving away your company's trade secrets. – dominicoder Mar 21 '23 at 21:49

1 Answers1

0

I went to the FCM documentation, found the section on Android, found the section on "Receive messages", and skimmed the page to find this:

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, 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.

dominicoder
  • 9,338
  • 1
  • 26
  • 32