【发布时间】:2016-06-26 03:44:11
【问题描述】:
如果应用程序已经通过深层链接打开,则深层链接将不起作用。
但是,如果我不是通过触发深层链接来打开应用程序,例如单击应用程序图标来打开应用程序。然后触发深层链接总是有效的。
这里是细节:
所以我在 AndroidManifest 中设置了这样的活动,即 LaunchActivity。
<activity
android:name="some.package.name.LaunchActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.SomeTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="dlscheme" android:host="dlhost" />
</intent-filter>
</activity>
在 LaunchActivity 中,我会在 onCreate() 中打印一个日志以表明它已经存在。
我用过
adb shell am start -W -a android.intent.action.VIEW -d "dlscheme://dlhost/param" some.package.name
测试深层链接。
应用程序被终止后,我使用了上述命令。它可以打开应用程序并路由到正确的活动,没问题。 并有以下日志。
adb shell am start -W -a android.intent.action.VIEW -d "dlscheme://dlhost/param" some.package.name
Starting: Intent { act=android.intent.action.VIEW dat=dlscheme://dlhost/param pkg=some.package.name }
Status: ok
Activity: some.package.name/.activity.LaunchActivity
ThisTime: 898
TotalTime: 898
WaitTime: 919
Complete
但是,如果我再次输入相同的命令,而不会终止应用程序。 它只会打开应用程序,但不会打开正确的活动,并产生以下日志。
adb shell am start -W -a android.intent.action.VIEW -d "dlscheme://dlhost/param" some.package.name
Starting: Intent { act=android.intent.action.VIEW dat=dlscheme://dlhost/param pkg=some.package.name }
Warning: Activity not started, its current task has been brought to the front
Status: ok
Activity: some.package.name/.activity.LaunchActivity
ThisTime: 0
TotalTime: 0
WaitTime: 6
Complete
加上这条额外的线
Warning: Activity not started, its current task has been brought to the front
我实际上也使用这个 chrome 意图在网站上尝试过这个:
intent://dlhost/param#Intent;scheme=dlscheme;package=some.package.name;end
它的行为是一样的。
【问题讨论】:
-
您是否在 logcat 中看到消息“设置上次选择的活动”?我看到了相同的行为,但该消息似乎表明此行为是有意的。
-
你是怎么决定的?
标签: android deep-linking