当我从链接打开我的应用程序时,如果它已经在堆栈上(打开),什么也没有发生。应用程序的现有实例打开,没有任何重定向。我发现这个意图的原因被称为。所以,我在 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 被调用两次,屏幕闪烁。问题是什么?
PS启动模式是单任务。