How can I reach the login screen from inner nav file

44 Views Asked by At

I'm a rookie in Kotlin and Android.

My application has two different navigation structures. The first one is a navigation file named main_activity_nav, which contains splash, login, signup, and main fragments. The second one is named bottom_bar_nav, which includes cart, profile,favorite, and home fragments.

Fragments of bottom_bar_nav(like Profile Fragment) are showed by a navhostfragment in main fragment(it's in main_activit_nav, you can see at the below image).

Structures like that

main_activity_nav bottom_bar_nav

You can think that main_activity_nav upper navigation,bottom_bar_nav's lower.

There is a button for signout in my profile fragment, and when I press it, I want to return to the login screen and delete all fragments in the backstack.

My button function

    binding.signOutButton.setOnClickListener {
        viewModel.signOut { result ->
            if (result) {
                //Navigation process (Profile to Login Fragment and clear backStack)
            }
        }
    }

I tried; val navHostFragment = requireActivity().supportFragmentManager.findFragmentById(R.id.mainFragment) as NavHostFragment navHostFragment.navController.navigate()

I tried some combination of these code but I got result null or junk

0

There are 0 best solutions below