Saturday, 6 November 2021

Pressing back always return to start destination using jetpack navigation

So, I have BottomNavigationView tied with Jetpack Navigation. Let say I have 4 bottom navigation menus, Fragment A, B, C, and D and A as the start destination. From Fragment A, I go to Fragment B, and then to Fragment C. Then, I pressed the hardware back button. I expected it to return to fragment B, instead, it return to Fragment A (which is the start destination).

This is the code:

val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main) as NavHostFragment
navController = navHostFragment.navController

binding.navView.setupWithNavController(navController)

How can I change the behavior?

Thanks~



from Pressing back always return to start destination using jetpack navigation

No comments:

Post a Comment