I have a BottomNavigationView
hooked up to 3 fragments (A, B and C) via the Navigation component. I also have a login fragment, which I am popping off the stack after successful login.
Observed navigation behavior:
A > B > C > A > B > C > B > Back > C > Back > B > Back > A > Back > Exit
Expected behavior:
(after reading comments of @ianhanniballake and Principles of navigation)
A > B > C > A > B > C > B > Back > A > Back > Exit
My problem is similar to circular navigation logic, but I have it in the BottomNavigationView
. How to achieve my expected behavior?
main_nav.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_nav"
app:startDestination="@id/login_fragment">
<fragment
android:id="@+id/login_fragment"
android:name="com.example.app.LoginFragment"
android:label="Login">
<action
android:id="@+id/login_action"
app:destination="@id/home_fragment"
app:launchSingleTop="true"
app:popUpTo="@id/main_nav"
app:popUpToInclusive="true" />
</fragment>
<!-- Fragments A, B and C tied to BottomNavigationView-->
</navigation>
BottomNavigationView
setup
navController = findNavController(R.id.main_nav_host)
mainActivityBinding.bottomNavView.setupWithNavController(navController)