问题描述
我有主要的导航:SplashFragment-> RegistrationFragment-> RootFragment
I have main navigation:SplashFragment -> RegistrationFragment -> RootFragment
<fragment
android:id="@+id/splashFragment"
android:name="com.low6.low6.features.splash.SplashFragment"
android:label="Splash"
tools:layout="@layout/fragment_splash" >
<action
android:id="@+id/action_next"
app:clearTask="true"
app:destination="@id/registrationFragment" />
</fragment>
<fragment
android:id="@+id/registrationFragment"
android:name="com.low6.low6.features.registration.RegistrationFragment"
android:label="Register">
<action
android:id="@+id/action_next"
app:clearTask="true"
app:destination="@id/rootFragment" />
</fragment>
<fragment
android:id="@+id/rootFragment"
android:name="com.low6.low6.core.RootFragment"
android:label="@string/home"
tools:layout="@layout/fragment_root" />
我已经嵌套了注册导航:RegistrationPersonalFragment-> RegistrationContactFragment-> RegistrationSecurityFragment
And I have nested registration navigation:RegistrationPersonalFragment -> RegistrationContactFragment -> RegistrationSecurityFragment
<fragment
android:id="@+id/registrationPersonalFragment"
android:name="com.low6.low6.features.registration.RegistrationPersonalFragment"
android:label="Register">
<action
android:id="@+id/action_next"
app:destination="@+id/registrationContactFragment" />
</fragment>
<fragment
android:id="@+id/registrationContactFragment"
android:name="com.low6.low6.features.registration.RegistrationContactFragment"
android:label="Register">
<action
android:id="@+id/action_next"
app:destination="@+id/registrationSecurityFragment" />
</fragment>
<fragment
android:id="@+id/registrationSecurityFragment"
android:name="com.low6.low6.features.registration.RegistrationSecurityFragment"
android:label="Register">
<action
android:id="@+id/action_next"
app:destination="@+id/rootFragment" />
</fragment>
如何使用Jetpack导航组件从最后嵌套的RegistrationSecurityFragment重定向到RootFragment?
How to redirect from the last nested RegistrationSecurityFragment to RootFragment using Jetpack Navigation component?
当前
<action
android:id="@+id/action_next"
app:destination="@+id/rootFragment" />
还有
navigateTo(R.id.action_next)
给我
java.lang.IllegalArgumentException: navigation destination com.xxx:id/rootFragment referenced from action com.xxx:id/action_next is unknown to this NavController
at androidx.navigation.NavController.navigate(NavController.java:691)
at androidx.navigation.NavController.navigate(NavController.java:648)
at androidx.navigation.NavController.navigate(NavController.java:634)
at com.xxx.core.BaseFragment.navigateTo(BaseFragment.kt:73)
at com.xxx.core.BaseFragment.navigateTo$default(BaseFragment.kt:66)
at com.xxx.features.registration.RegistrationSecurityFragment$epoxyController$1$$special$$inlined$button$lambda$1.onClick(RegistrationSecurityFragment.kt:106)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
推荐答案
如果您有多个导航图,请确保使用正确的导航控制器.在某些情况下,使用Navigation.findNavController(view)可能需要获取根视图以获取根的导航.希望会对您有所帮助.
If you have more than one navigation graph, please make sure you're using the right navigation controller. Using Navigation.findNavController(view) in some cases you might need to get your root view to get the root's navigation. Hope, this'll help.
这篇关于如何使用Jetpack导航从嵌套片段导航到父片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!