【发布时间】:2019-11-19 05:51:35
【问题描述】:
当我从链接打开我的应用程序时,如果它已经在堆栈上(打开),没有任何反应。应用程序的现有实例打开,没有任何重定向。我发现这个意图的原因被称为。所以,我在 onNewIntent 方法中添加了 setIntent(newIntent) ,但它没有帮助。然后我添加了以下代码:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
//did not help
//setIntent(intent)
findNavController(R.id.container).handleDeepLink(intent)
}
但是,onNewIntent 被调用了两次。点击链接后的日志结果为:(存在应用实例时)
2019-11-19 10:43:18.758 D/CORN_DEBUG: onNewIntent
2019-11-19 10:43:18.805 D/CORN_DEBUG: onNewIntent
2019-11-19 10:43:19.248 D/CORN_DEBUG: onCreate Main Activity
否则,结果为:
2019-11-19 10:45:05.272 D/CORN_DEBUG: onCreate Main Activity
2019-11-19 10:45:05.524 D/CORN_DEBUG: onNewIntent
2019-11-19 10:45:06.041 D/CORN_DEBUG: onCreate Main Activity
当 onCreate 被调用两次时,屏幕会闪烁。有什么问题?
附:启动模式为单任务。
【问题讨论】:
标签: android kotlin android-architecture-navigation android-deep-link