Jump between two navigation graphs

Viewed 146

For navigation, I use the Navigation The component I connected to it using the Navigation Extension BottomNavigationView. I tried to switch from one graph to another, but he always showed me an error that he could not find a path where to go. If the way to go from one graph to another

the code where the Navigation Component and bottomNavView are connected

class MainActivity : AppCompatActivity(R.layout.activity_main) {

    private lateinit var appBarConfiguration: AppBarConfiguration
    private var currentNavController: LiveData<NavController>? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;


        if (savedInstanceState == null) {
            initNavigationComponent()

        }
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        
        initNavigationComponent()
    }

    override fun onSupportNavigateUp(): Boolean {
        return currentNavController?.value?.navigateUp(appBarConfiguration) ?: false
                || super.onSupportNavigateUp()
    }

    private fun initNavigationComponent() {

        appBarConfiguration =
            AppBarConfiguration(setOf(R.id.auth_fragment, R.id.main_screen_fragment))

        setSupportActionBar(toolbar)

        val navGraphIds =
            listOf(R.navigation.nav_main, R.navigation.nav_catalog, R.navigation.nav_profile)

        // Setup the bottom navigation view with a list of navigation graphs
        val controller = bottom_nav.setupWithNavController(
            navGraphIds = navGraphIds,
            fragmentManager = supportFragmentManager,
            containerId = R.id.main_nav_fragment,
            intent = intent
        )

        controller.observe(this, { navController ->
            setupActionBarWithNavController(navController,appBarConfiguration)

            collapsingToolbarLayout.setupWithNavController(
                toolbar,
                navController,
                appBarConfiguration
            )

            navController.addOnDestinationChangedListener {...} )

        currentNavController = controller

    }
}

Tried connecting with <include app:graph = "@navigation/myGraph" /> but that doesn't work either

1 Answers
Related