问题描述
我的目标:我想向用户发送推送通知。当用户点击该通知时,用户应导航到名为 HitoryDetailsFragment 的特定片段。
我所做的:我实现了 FirebaseInstanceIdService 和 FirebaseMessagingService,并且能够捕获从后端服务器发送的 Firebase 消息。我通过“隐式深层链接”实现了深层链接。我使用嵌套导航图实现了导航。与历史相关的屏幕放置在单独的导航图 graph_history.xml 中。
问题是什么:当应用程序打开时,一切正常。我点击通知 -> 我被重定向到 HistoryDetailFragment,当我按下后退按钮时,它会返回到 HistoryListFragment。但是当应用程序关闭时(不在最近的应用程序托盘中),而不是 HistoryDetailsFragment,SplashFragment 被打开,之后我被重定向到 HomeFragment(这是正确的,因为这就是流程应该如何工作)。但是,当应用程序关闭时,如何将用户重定向到 HistoryDetails?此外,我应该显示一个 Pin 屏幕,用户应该在其中输入他的 pin,如果他之前没有,在显示 HistoryDetailsFragment 之前。
我的代码如下。
private fun createPendingIntent(history: History?) = NavDeepLinkBuilder(this).run {
setGraph(R.navigation.graph_main)
history?.let {
//todo when the app is not open (not in tray of recent apps),this destination does not work
//this instead navigates to SplashFragment
//which is correct,because we have not entered the pin,so we are not entitled to open the history detail screen
//but how do I handle this case?
setDestination(if (it.type.isNews) R.id.nav_history_news else R.id.nav_history_detail)
setArguments(if (it.type.isNews) HistoryNewsFragmentArgs(it.link).toBundle() else HistoryDetailFragmentArgs(it.id).toBundle())
}
createPendingIntent()
}
历史图表:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)