I am using NavDeepLinkBuilder to generate a pending intent for a push notification to open the app at a particular destination.
return NavDeepLinkBuilder(this)
.setComponentName(MainActivity::class.java)
.setGraph(R.navigation.main_navigation)
.setDestination(destinationId)
.setArguments(args)
.createPendingIntent()
When the app is in the foreground, the notification will navigate to the destination set in the pending intent built by the NavDeepLinkBuilder. 👍
However when the app is not in the foreground, the notification will only navigate to the MainActivity and ignore the destination set in the NavDeepLinkBuilder. 👎
Note: The pending intent and notification are built in a service extending FirebaseMessagingService.
Yes, if you using firebase you can face this behavior. The problem is that your onMessageRecived()
method never triggers when your app in the background. In these cases you will receive your firebase message not in onMessageRecived()
but in MainActivity()
instead. Just check your intent in onCreate() method as I described in my own question here in edit block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With