导航体系结构:不建议使用clearTask时如何管理正确的导航 [英] Navigation architecture: How to manage proper navigation without using clearTask as it is deprecated

本文介绍了导航体系结构:不建议使用clearTask时如何管理正确的导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此处中的导航架构时,

While using navigation architecture as from here , here clearTask is deprecated.

我的情况是这样的:登录"和注册"共有2个屏幕,两者都有相互链接.因此,您可以从登录名"转到注册",也可以从注册名"登录. 但背面应关闭Press App.

My scenario is this: There are 2 screens Login and Registration, both have links to each other. So you can go to Registration from Login and also Login from Registration. But on back Press App should be closed.

只需在以下两个动作中添加clearTask即可完成.

It could simply be done by just adding clearTask to both actions as below.

<?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>

但是不建议使用,我尝试了其他解决方案,例如添加 popUpTo->导航图的ID ,使两个操作中的 launchSingleTop都变为真实.在我的情况下,似乎什么都没用.

But as it was deprecated I have tried other solution like adding popUpTo -> navigation graph's Id, making launchSingleTop to true in both actions. Nothing seems to work in my scenario.

我已经检查了这个问题也没有解决.

I have checked this question also but didn't get a solution.

推荐答案

您需要在操作中使用下一个代码

You need to use in your action next code

app:popUpTo="@+id/fragment_login"
app:popUpToInclusive="true"

这篇关于导航体系结构:不建议使用clearTask时如何管理正确的导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆