这一次,我需要您与Deeplink结合使用Android导航组件的帮助。
我一直在关注此documentation,并且fragment和deeplink之间的连接正常。
问题在于接收深层链接的活动。就我而言,我设置了android:launchMode =“ singleTask”
<activity android:name=".features.welcome.WelcomeActivity"
android:launchMode="singleTask">
<nav-graph android:value="@navigation/welcome_nav_graph" />
</activity>
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Timber.d("onNewIntent: $intent with activity: $this")
navController.handleDeepLink(intent)
}
通过这种配置,我注意到了一些奇怪的行为:
每次单击深层链接时,WelcomeActivity都会收到两次onNewIntent调用。有时甚至创建了该活动的新实例。
1_ object1-onNewIntent
2_ object1-onNewIntent
3_ object2-onCreate
这里有一些日志:
首次启动
onCreate:Intent {flg = 0x10000000具有活动的cmp = {applicationId} / {package} .WelcomeActivity}:{package}。WelcomeActivity@ 4adbef0
打开深层链接
onNewIntent:意图{act = android.intent.action.VIEWcat = [android.intent.category.BROWSABLE] dat = https:// {depp_link}…flg = 0x10010000 cmp = {applicationId} / {package}。WelcomeActivity(具有活动):{package} .WelcomeActivity @ 4adbef0
onNewIntent:意图{act = android.intent.action.VIEWcat = [android.intent.category.BROWSABLE] dat = https:// {depp_link} ...flg = 0x1001c000 cmp = {applicationId} / {package}。WelcomeActivity(具有活动):{package} .WelcomeActivity @ 4adbef0
onCreate:Intent {act = android.intent.action.VIEWcat = [android.intent.category.BROWSABLE] dat = https:// {depp_link} ...flg = 0x1001c000 cmp = {applicationId} / {package}。WelcomeActivity(具有活动):{package} .WelcomeActivity @ b77c6b
杀死应用并打开深层链接
onCreate:Intent {act = android.intent.action.VIEWcat = [android.intent.category.BROWSABLE] dat = https:// {depp_link} ...flg = 0x10018000 cmp = {applicationId} / {package}。WelcomeActivity(具有活动):{package} .WelcomeActivity @ b78f4df
onNewIntent:意图{act = android.intent.action.VIEWcat = [android.intent.category.BROWSABLE] dat = https:// {depp_link} ...flg = 0x1001c000 cmp = {applicationId} / {package}。WelcomeActivity(具有活动):{package} .WelcomeActivity @ b78f4df
onCreate:Intent {act = android.intent.action.VIEWcat = [android.intent.category.BROWSABLE] dat = https:// {depp_link} ...flg = 0x1001c000 cmp = {applicationId} / {package}。WelcomeActivity(具有{package}。WelcomeActivity@ dfe87b2
更新:
1-似乎启动模式与此问题无关。我注意到默认启动模式也是如此。
2- navController.navigate(intent.dataString.toUri())似乎可以正常工作。所以我想问题出在navController.handleDeepLink(intent)。
这一次,我需要您与Deeplink结合使用Android导航组件的帮助。我一直在关注本文档,fragment和deeplink之间的连接正常。 ...
测试不同的更改,我得出的结论是“ navController.handleDeepLink(intent)”正在引起这种奇怪的行为。