本文介绍了导航组件 popUpTo 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我遇到了关于

<动作android:id="@+id/action_collection_fragment_to_view_fragment"app:destination="@+id/view_fragment"/></片段><fragment android:id="@+id/view_fragment"><动作android:id="@+id/action_view_fragment_to_edit_fragment"app:destination="@id/edit_fragment"/><argument android:name="item"/></片段><fragment android:id="@+id/edit_fragment"><动作android:id="@+id/action_edit_fragment_to_view_fragment"应用程序:目的地=@id/view_fragment"app:popUpTo="@id/collection_fragment"/><argument android:name="item"/></片段>

堆栈跟踪:

java.lang.IllegalArgumentException:导航目标 com.domain.application:id/action_collection_fragment_to_view_fragment 对这个 NavController 是未知的在 androidx.navigation.NavController.navigate(NavController.java:669)在 androidx.navigation.NavController.navigate(NavController.java:628)在 com.domain.application.CollectionFragment$onActivityCreated$4.onChanged(CollectionFragment.kt:126)在 com.domain.application.CollectionFragment$onActivityCreated$4.onChanged(CollectionFragment.kt:28)在 com.domain.application.common.SingleLiveEvent$observe$1.onChanged(SingleLiveEvent.kt:20)在 android.arch.lifecycle.LiveData.thinkNotify(LiveData.java:109)在 android.arch.lifecycle.LiveData.dispatchingValue(LiveData.java:126)在 android.arch.lifecycle.LiveData.setValue(LiveData.java:282)在 android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)在 com.domain.application.common.SingleLiveEvent.setValue(SingleLiveEvent.kt:27)在 android.arch.lifecycle.LiveData$1.run(LiveData.java:87)在 android.os.Handler.handleCallback(Handler.java:789)在 android.os.Handler.dispatchMessage(Handler.java:98)在 android.os.Looper.loop(Looper.java:164)在 android.app.ActivityThread.main(ActivityThread.java:6938)在 java.lang.reflect.Method.invoke(Native Method)在 com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
解决方案

这是 alpha04 版本中的错误,已在 alpha05 中修复 https://issuetracker.google.com/issues/111907708

Recently I ran into issue that I asked about here

But when trying to figure out what's happening I always stumble on the same problem.

Here's what I have - I have a collection, preview, edit fragments than I need to navigate between.

But after navigating from edit fragment to preview fragment I want the back button to take user to collection fragment instead of edit fragment, and it does that, but when trying to navigate further it crashes because the destination is said to be (view_fragment). Why is that, is it some sort of bug?

<fragment android:id="@+id/collection_fragment">
    <action
        android:id="@+id/action_collection_fragment_to_view_fragment"
        app:destination="@+id/view_fragment" />
</fragment>

<fragment android:id="@+id/view_fragment">
    <action
        android:id="@+id/action_view_fragment_to_edit_fragment"
        app:destination="@id/edit_fragment" />
    <argument android:name="item" />
</fragment>

<fragment android:id="@+id/edit_fragment">
    <action
        android:id="@+id/action_edit_fragment_to_view_fragment"
        app:destination="@id/view_fragment"
        app:popUpTo="@id/collection_fragment" />
    <argument android:name="item" />
</fragment>

EDIT:

Stack trace:

java.lang.IllegalArgumentException: navigation destination com.domain.application:id/action_collection_fragment_to_view_fragment is unknown to this NavController
    at androidx.navigation.NavController.navigate(NavController.java:669)
    at androidx.navigation.NavController.navigate(NavController.java:628)
    at com.domain.application.CollectionFragment$onActivityCreated$4.onChanged(CollectionFragment.kt:126)
    at com.domain.application.CollectionFragment$onActivityCreated$4.onChanged(CollectionFragment.kt:28)
    at com.domain.application.common.SingleLiveEvent$observe$1.onChanged(SingleLiveEvent.kt:20)
    at android.arch.lifecycle.LiveData.considerNotify(LiveData.java:109)
    at android.arch.lifecycle.LiveData.dispatchingValue(LiveData.java:126)
    at android.arch.lifecycle.LiveData.setValue(LiveData.java:282)
    at android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)
    at com.domain.application.common.SingleLiveEvent.setValue(SingleLiveEvent.kt:27)
    at android.arch.lifecycle.LiveData$1.run(LiveData.java:87)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
解决方案

This was a bug in alpha04 version it's fixed in alpha05 https://issuetracker.google.com/issues/111907708

这篇关于导航组件 popUpTo 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:56