so I'm using the android navigation component and I have a problem (2.2.0-rc04 version).
I have a welcomeFragment(wF). From wF I want to navigate to loginSellerFragment(lSF) which is in a different navigation graph. I also don't want to remove wF from backstack ( popUpTo, popUpToInclusive) when navigating to lSF because a user might wanna go back to it.
<fragment android:id="@+id/welcomeFragment"> <action android:id="@+id/action_welcomeFragment_to_nav_onboarding_seller" app:launchSingleTop="true" app:destination="@id/nav_onboarding_seller" /> </fragment> After navigating to lSF the backstack looks like this : wF lSF
We're on lSF now, after login we want to go to feedFragment(fF) which again is in a separate graph, but this time we want to clear all the backstack, because if a user is logged in and presses back he wants the app to exit, not to take him back to wF or lSF, so I used popUpTo="@id/loginSellerFragment popUpToInclusive='true" in the action from lSF to fF.
<fragment android:id="@+id/loginSellerFragment"> <action android:id="@+id/action_login_to_seller" app:destination="@+id/seller" . //this is the graph that has as firstDestination, feedFragment app:launchSingleTop="true" app:popUpTo="@id/loginSellerFragment" app:popUpToInclusive="true" /> </fragment> So in the backstack in this moment should be only fF because we removed everything up to lSF(lSF included)
The problem
When I'm on fF and press back, the app doesn't close, instead it takes me to wF ( wF should have been popped off the backstack already)
What I've tried
I've tried instead of popUpTo="@id/loginSellerFragment popUpToInclusive='true" to use popUpTo="@id/welcomeFragment popUpToInclusive='true" and it worked fine, but I'm pretty sure that this is not how it should be done. What am I missing here guys? Am I building the backstack wrong?
Also I've tried adding popUpTo="@id/welcomeFragment popUpToInclusive='true" after navigating from wF to lSF , but this will break my user experience, because I don't want the app to exit when I'm still in the login process.
Please note that all of this fragments are in separate graphs. To navigate I use FragmentDirections e.g : findNavController.navigate(WelcomeFramgentDirections.actionXtoY())