Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavDeepLinkBuilder destination ignored when app not in foreground

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.

like image 253
oznecro Avatar asked Oct 01 '19 06:10

oznecro


1 Answers

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

like image 129
Dwane13 Avatar answered Nov 15 '22 19:11

Dwane13