【发布时间】:2020-01-22 09:44:12
【问题描述】:
所以我使用的是android导航组件,但我遇到了问题(2.2.0-rc04版本)。
我有一个welcomeFragment(wF)。从wF 我想导航到位于不同导航图中的loginSellerFragment(lSF)。我也不想在导航到lSF 时从后台堆栈(popUpTo、popUpToInclusive)中删除wF,因为用户可能想返回它。
<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>
导航到 lSF 后,backstack 如下所示:wF lSF
我们现在在lSF,登录后我们想转到feedFragment(fF),它又在一个单独的图表中,但是这次我们要清除所有的后台堆栈,因为如果用户登录in 并按回他希望应用程序退出,而不是让他回到wF 或lSF,所以我在从lSF 到fF 的动作中使用了popUpTo="@id/loginSellerFragment popUpToInclusive='true"。
<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>
所以此时在后台应该只有fF,因为我们删除了直到lSF(包括lSF)的所有内容
问题
当我在fF 上并按回时,应用程序不会关闭,而是将我带到wF(wF 应该已经从后台弹出)
我的尝试
我已经尝试使用popUpTo="@id/welcomeFragment popUpToInclusive='true" 代替popUpTo="@id/loginSellerFragment popUpToInclusive='true" 并且效果很好,但我很确定这不是应该的方式。我在这里想念什么?我是否构建了错误的后台堆栈?
我还尝试在从 wF 导航到 lSF 后添加 popUpTo="@id/welcomeFragment popUpToInclusive='true" ,但这会破坏我的用户体验,因为我不希望应用程序在我仍在登录过程中时退出.
请注意,所有这些片段都在单独的图表中。
要导航,我使用FragmentDirections 例如:findNavController.navigate(WelcomeFramgentDirections.actionXtoY())
【问题讨论】:
标签: android android-fragments android-navigation