当用户单击通知时,我需要导航到一个片段。
如果该应用正在运行,则可以正常运行。但是,当我退出该应用程序,然后单击通知时,它会崩溃并显示以下错误消息:
2020-04-24 18:06:49.607 14832-14832/com.package.name E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.package.name, PID: 14832
java.lang.IllegalStateException: no current navigation node
at androidx.navigation.NavController.navigate(NavController.java:824)
at androidx.navigation.NavController.navigate(NavController.java:804)
at androidx.navigation.NavController.navigate(NavController.java:790)
at androidx.navigation.NavController.navigate(NavController.java:985)
at com.package.name.core.navigation.NavigationActivity.handleNewIntent(NavigationActivity.kt:358)
at com.package.name.core.navigation.NavigationActivity.onPostCreate(NavigationActivity.kt:257)
at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1385)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3088)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我的导航代码:
navController.navigate(
navigateToFragment(
someParam = "some value",
someOtherParam = "other value"
)
)
我的navController如何实例化
private val navController: NavController by lazy {
Navigation.findNavController(this, R.id.nav_host_fragment)
}
我猜这是由于我的navController没有正确初始化吗?任何想法如何解决此问题/什么是正确的方法?
答案 0 :(得分:0)
我找到了解决方法。
缺少的是为我的navcontroller设置开始目标,像这样:
graph = navGraph.apply { startDestination = destinationId }
currentDestination?.let { applyDestinationPropertiesToToolbar(it) }