6 android kotlin android-architecture-navigation android-deep-link
当我从链接打开我的应用程序时,如果它已经在堆栈上(打开),什么也不会发生。应用程序的现有实例被打开,没有任何重定向。我发现这个意图的原因被称为。所以,我在 onNewIntent 方法中添加了 setIntent(newIntent) ,但它没有帮助。然后我添加了以下代码:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
//did not help
//setIntent(intent)
findNavController(R.id.container).handleDeepLink(intent)
}
Run Code Online (Sandbox Code Playgroud)
但是,然后 onNewIntent 被调用两次。点击链接后的日志结果为:(存在app实例时)
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
Run Code Online (Sandbox Code Playgroud)
否则,结果是:
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
Run Code Online (Sandbox Code Playgroud)
由于 onCreate 被调用两次,屏幕闪烁。问题是什么?
PS 启动模式是单任务。
小智 0
处理深层链接 强烈建议在使用导航时始终使用标准的默认启动模式。当使用标准启动模式时,Navigation 通过调用handleDeepLink() 来自动处理深层链接,以处理 Intent 中的任何显式或隐式深层链接。但是,如果在使用备用启动模式(例如 singleTop)时重新使用 Activity,则不会自动发生这种情况。这种情况下,需要在onNewIntent()中手动调用handleDeepLink(),如下例所示:
https://developer.android.com/guide/navigation/navigation-deep-link#handle
归档时间: |
|
查看次数: |
448 次 |
最近记录: |