Reputation: 233
I'm trying to use the new Jetpack navigation component. I use a BottomNavigationView with the navController : NavigationUI.setupWithNavController(bottomNavigation, navController)
But when I'm switching fragments, each fragment will be reloaded! is there any way to stop fragment reloading/refreshment?
Upvotes: 5
Views: 1674
Reputation: 66
I had problems with reloading also. This helped me.
override fun onCreate(savedInstanceState: Bundle?) {
...
val navController = Navigation.findNavController(this, R.id.mainFragment)
bottomNavigation.setOnNavigationItemSelectedListener {
if (it.itemId != bottomNavigation.selectedItemId)
NavigationUI.onNavDestinationSelected(it, navController)
true
}
This this stopped reloading on multiple clicks on bottom navigation item.
Upvotes: 3