【发布时间】:2021-12-12 18:56:44
【问题描述】:
我想通过以下功能改进我的代码: -> 点击通知后直接进入片段
我基本上使用导航组件来导航片段。只有当我的应用程序从后台关闭时,它才能在单击通知后转到我的活动的第一页。 应用程序是一个包含许多片段的活动。
当我的应用程序在其他一些片段上时,它会崩溃。
java.lang.IllegalArgumentException: Navigation destination com.example.program:id/action_global_MyGoalFragment cannot be found in the navigation graph NavGraph(com.example.program:id/nav_main_graph) startDestination={NavDestination(com.example.program:id/MyGoalFragment) label=MyGoalFragment}
这是我的代码:
val pendingIntent2 = NavDeepLinkBuilder(applicationContext)
.setComponentName(MainActivity::class.java)
.setGraph(R.navigation.nav_main_graph)
.setDestination(R.id.action_global_MyGoalFragment)
.createPendingIntent()
编辑: 我找到了有人使用的方法。我知道 setArguments(bundle) 可用于将一些数据从片段发送到另一个片段,例如列表的位置等。
NavDeepLinkBuilder pending intent dosent work when app in background
你知道如何解决我的问题吗?
【问题讨论】: