我正在使用新的导航组件库(版本 2.4.0-alpha01),它引入了对多个返回堆栈的支持。
我的问题是:如何以编程方式导航到任何 Fragment 返回堆栈中的任何目的地?
以 Google 的 NavigationAdvancedSample 项目为例,我想从 Title 片段导航到 UserProfile 片段,它们属于底部导航栏中的单独菜单项。
在标题片段中创建 XML 操作并调用 findNavController().navigate(R.id.action_title_to_leaderboard)
导致以下错误:
java.lang.IllegalArgumentException: Navigation destination com.example.android.navigationadvancedsample:id/leaderboard referenced from action com.example.android.navigationadvancedsample:id/action_title_to_leaderboard cannot be found from the current destination Destination(com.example.android.navigationadvancedsample:id/titleScreen) label=Home class=com.example.android.navigationadvancedsample.homescreen.Title
at androidx.navigation.NavController.navigate(NavController.kt:1190)
at androidx.navigation.NavController.navigate(NavController.kt:1128)
at androidx.navigation.NavController.navigate(NavController.kt:1110)
at androidx.navigation.NavController.navigate(NavController.kt:1093)
at com.example.android.navigationadvancedsample.homescreen.Title$onCreateView$1.onClick(Title.kt:38)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
导航 2.4.0-alpha01 版本是否支持?