问题
I am using the Android Navigation Components and am facing one weird issue. I am not able to clear the back stack for the up button, no matter what I tried.
My Navigation graph looks like this:
Let's take the LoginFragment for example,
<fragment
android:id="@+id/loginFragment"
android:name="com.yashovardhan99.firebaselogin.LoginFragment"
android:label="Login"
tools:layout="@layout/fragment_login" >
<action
android:id="@+id/action_loginFragment_to_welcomeFragment"
app:destination="@id/welcomeFragment"
app:popUpTo="@+id/nav_graph"
app:popUpToInclusive="true" />
</fragment>
The Java code to navigate is:
navController.navigate(
LoginFragmentDirections.actionLoginFragmentToWelcomeFragment());
I have set the PopUpTo to the graph ID and set Inclusive to true. This should clear the back stack when moving to WelcomeFragment. However, the WelcomeFragment still shows the Up button on the action bar and pressing it takes me back to the PreLoginFragment (which is the home destination for the graph). Strangely, pressing the back button takes me out of the app as expected.
来源:https://stackoverflow.com/questions/56625934/unable-to-clear-the-back-stack-of-all-fragments-with-navigation-components