Predict the output
The app is in the background. The server sends a message with both a notification and a data payload. What happens?
class PushService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
log("received ${message.data}")
}
override fun onNewToken(token: String) {
log("new token")
}
}Hint 1 of 1
Who handles notification payloads when the app is backgrounded?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A The system shows the notification; onMessageReceived isn't called, and data arrives in the launch intent on tap
Correct. In the background, notification payloads are handled by the system tray.
Why not the others?
- B onMessageReceived runs and the app must build the notification. That's what happens for data-only messages, or in the foreground.
- C Nothing is shown until the app is opened. The system shows notification messages for you.
- D Both the system and onMessageReceived show a notification. Only one path handles it.