Unable to clear the back stack of all fragments with Navigation Components

倖福魔咒の 提交于 2019-12-07 13:11:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!