问题
My app has just two destinations, FirstFragment and SecondFragment. I created an url Deep Link for the SecondFragment and it works fine.
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.
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!")
}
回答1:
The DeepLink knows about your NavGraph. And if your SecondFragment is a decendent of the FirstFragment, this is the intended behavior.
When you show your NavGraph and how you create the DeepLink it might be possible to suggest a different option.
来源:https://stackoverflow.com/questions/64687574/android-navigation-url-deep-link-back-to-previous-app