相关疑难解决方法(0)

导航架构:如何在不使用 clearTask 的情况下管理正确的导航,因为它已被弃用

此处开始使用导航架构时,不推荐使用此处的clearTask。

我的场景是这样的:有 2 个屏幕登录和注册,两者都有彼此的链接。所以你可以从登录进入注册,也可以从注册登录。但在后面 Press App 应该关闭。

只需将 clearTask 添加到以下两个操作即可轻松完成。

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/nv_auth_phase"
    app:startDestination="@id/fragment_login">

    <fragment
        android:id="@+id/fragment_login"
        android:name="com.jobhook.ui.auth.login.LoginFragment"
        android:label="LoginFragment"
        tools:layout="@layout/fragment_login">
        <action
            android:id="@+id/nv_action_login_to_registration"
            app:clearTask="true"
            app:destination="@id/fragment_registration" />

    </fragment>


    <fragment
        android:id="@+id/fragment_registration"
        android:name="com.jobhook.ui.auth.registration.RegistrationFragment"
        android:label="RegistrationFragment"
        tools:layout="@layout/fragment_registration">


        <action
            android:id="@+id/nv_action_registration_to_login"
            app:clearTask="true"
            app:destination="@id/fragment_login" />
    </fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)

但是由于它已被弃用,我尝试了其他解决方案,例如添加popUpTo -> 导航图的 Id,使两个操作中的 launchSingleTop 都为 true。在我的场景中似乎没有任何效果。

我也检查了这个问题,但没有得到解决方案。

android android-fragments android-architecture-components android-architecture-navigation

5
推荐指数
1
解决办法
2196
查看次数