0

I have a NavigationView (Drawer) with 5 menus each pointing to 5 different fragments. Say Fragment A,B,C,D,E.

Now I want to navigate to fragment C on clicking a notification (Pending Intent)

This is my deepLink

return NavDeepLinkBuilder(this)
            .setComponentName(MainActivity::class.java)
            .setGraph(R.navigation.mobile_navigation)
            .setDestination(R.id.nav_fragment_c)
            .setArguments(args)
            .createPendingIntent()

It navigates to the fragment but suppose the user is currently on fragment A, the deep link adds the fragment on top of fragment A and won't let the user navigate back to fragment A even on clicking the drawer menu A (behaves like it's disabled). However, on clicking the back button it takes the user back to fragment A and everything works fine again (I guess it pops the fragment).

Am I doing something wrong here? How do I tell the navController to navigate to the desired fragment without adding it on top of whichever fragment the user is currently on.

Also noticed the same behavior when I do navController.navigate(destinationId)

Here is my navContoller

val navController = findNavController(R.id.nav_host_fragment_content_main)
        binding.navView?.let {
            appBarConfiguration = AppBarConfiguration(
                setOf(
                    R.id.nav_fragment_a,
                    R.id.nav_fragment_b,
                    R.id.nav_fragment_c,
                    R.id.nav_fragment_d,
                    R.id.nav_fragment_e,
                ),
                binding.drawerLayout
            )
            setupActionBarWithNavController(navController, appBarConfiguration)
            it.setupWithNavController(navController)
        }
Vebito
  • 154
  • 1
  • 10
  • What version of Navigation are you using and what does your navigation graph look like? – ianhanniballake Jun 01 '22 at 02:14
  • @ianhanniballake I'm on version 2.4.2. My readings suggests it has something to do with multiple backstack but I'm not sure how to go about fixing that. And my nav graph is just flat, one layer (the default one generated by android studio for Navigation Drawer activity) And I have a single MainActivity hosting those fragments. – Vebito Jun 01 '22 at 07:26
  • All top level destinations I should say (With navigation drawer) – Vebito Jun 01 '22 at 07:35

0 Answers0