bottom navigation view fragment re-created when selected tab

261 Views Asked by At

In my application i am using Jetpack Navigation with BottomNavigationView. I have like 5 fragments and when i am in Home fragment, i click tab2 item in bottom navigation view and i click tab1 again, it re-creates the fragment.

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

    navController = navHostFragment.navController
    navController.addOnDestinationChangedListener { _, destination, _ ->
        currentNavId = destination.id
    }
    binding.bottomNav.setupWithNavController(navHostFragment.navController)
    binding.bottomNav.apply {
        setupWithNavController(navController)
        setOnItemReselectedListener { }
    }

enter image description here

0

There are 0 best solutions below