Mih*_*o K 6 android android-jetpack android-architecture-navigation
我已从连接到 NavController 的导航抽屉导航到DialogFragment 。但是,当我导航到已设置 popUpTo 和包含对话框片段的另一个目的地时,它不会清除堆栈。如何清除堆栈?
AM 从 LogoutDialog 调用此方法
findNavController().navigate(R.id.action_logoutDialog_to_auth_navigation)
我正在使用片段并且仅使用一项活动。
这是我的导航图的一部分
<fragment
android:id="@+id/homeFragment"
android:name="io.ui.home.HomeFragment"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_homeFragment_to_auth_navigation"
app:destination="@id/auth_navigation"
app:popUpTo="@id/homeFragment"
app:popUpToInclusive="true" />
<argument
android:name="fromLogin"
app:argType="boolean"
android:defaultValue="false" />
</fragment>
<dialog
android:id="@+id/logoutDialog"
android:name="io.ui.dialog.LogoutDialog"
android:label="LogoutDialog" >
<action
android:id="@+id/action_logoutDialog_to_auth_navigation"
app:destination="@id/auth_navigation"
app:popUpTo="@id/logoutDialog"
app:popUpToInclusive="true" />
</dialog>
<!-- auth navigation graph -->
<navigation
android:id="@+id/auth_navigation"
app:startDestination="@id/loginFragment">
<fragment
android:id="@+id/loginFragment"
android:name="io.ui.login.LoginFragment"
android:label="fragment_login"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/action_loginFragment_to_OTPFragment"
app:destination="@id/OTPFragment"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_loginFragment_to_homeFragment"
app:destination="@id/homeFragment" />
<action
android:id="@+id/action_loginFragment_to_resetPasswordFragment"
app:destination="@id/resetPasswordFragment" />
</fragment>
<fragment
android:id="@+id/OTPFragment"
android:name="io.ui.login.OTPFragment"
android:label="fragment_otp"
tools:layout="@layout/fragment_otp">
<action
android:id="@+id/action_OTPFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:popUpTo="@id/OTPFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_OTPFragment_to_loginFragment"
app:destination="@id/loginFragment"
app:popUpTo="@id/OTPFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/resetPasswordFragment"
android:name="io.ui.profile.PasswordFragment"
android:label="fragment_reset_password"
tools:layout="@layout/fragment_password" >
<argument
android:name="isReset"
app:argType="boolean"
android:defaultValue="false" />
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
Bis*_*uit 14
您正在寻找这些属性来投入您的行动中。
操作的属性popUpTo在导航之前将返回堆栈“弹出”到给定的目的地。(目的地将从后堆栈中删除。)
如果该popUpToInclusive属性为 false 或未设置,popUpTo则删除指定目标之前的目标,但将指定目标保留在返回堆栈中。
如果popUpToInclusive设置为 true,则该popUpTo属性将从返回堆栈中删除直到给定目的地(包括给定目的地)的所有目的地。
如果popUpToInclusive为 true 并popUpTo设置为应用程序的起始位置,则该操作将从返回堆栈中删除所有应用程序目标。“后退”按钮可让用户完全退出应用程序。
编辑:另外,我还添加了这个非常棒的视频,它通过示例进行了解释https://www.youtube.com/watch?v=mLfWvSGG5c8
| 归档时间: |
|
| 查看次数: |
13610 次 |
| 最近记录: |