Android Navigation Url Deep Link Back to Previous App [英] Android Navigation Url Deep Link Back to Previous App
问题描述
我的应用只有两个目的地,FirstFragment 和 SecondFragment.我为 SecondFragment 创建了一个 url 深层链接,它工作正常.
My app has just two destinations, FirstFragment and SecondFragment. I created an url Deep Link for the SecondFragment and it works fine.
我想要的是,在我从 Deep Link 进入 SecondFragment 后,我想在按下返回按钮时回到上一个应用程序.但现在它总是回到 FirstFragment.
What I want is, after I enter the SecondFragment from the Deep Link, I want to go back to the previous app when I press the Back button. But now it always go back to the FirstFragment.
我已经在 launchMode
上将我的 MainActivity 设置为 singleTask
并尝试了以下但不起作用:
I have set my MainActivity to singleTask
on launchMode
and tried the following but doesn't work:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent!!.flags = Intent.FLAG_ACTIVITY_NEW_TASK
navController.handleDeepLink(intent)
Log.v("MainActivity", "onNewIntent() get called!")
}
推荐答案
DeepLink 了解您的 NavGraph.如果您的 SecondFragment 是 FirstFragment 的继承者,这就是预期的行为.
The DeepLink knows about your NavGraph. And if your SecondFragment is a decendent of the FirstFragment, this is the intended behavior.
当您展示您的 NavGraph 以及您如何创建 DeepLink 时,可能会建议不同的选项.
When you show your NavGraph and how you create the DeepLink it might be possible to suggest a different option.
这篇关于Android Navigation Url Deep Link Back to Previous App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!