Shi*_*ing 52 android deep-linking
如果已通过深层链接打开应用程序,则深层链接不起作用.
但是,如果我打开应用程序而不是通过触发深层链接,例如单击应用程序图标以打开应用程序.然后在之后触发deeplink将始终有效.
这里有详细信息:
所以我在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>
Run Code Online (Sandbox Code Playgroud)
在LaunchActivity中,我会在onCreate()中打印一个日志,表明它已存在.
我用了
adb shell am start -W -a android.intent.action.VIEW -d "dlscheme://dlhost/param" some.package.name
Run Code Online (Sandbox Code Playgroud)
测试深层链接.
随着应用程序被杀,我使用了上面的命令.它可以打开应用程序并路由到正确的活动,没问题.并有以下日志.
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
Run Code Online (Sandbox Code Playgroud)
但是,如果我再次输入相同的命令,而不会杀死应用程序.它只会打开应用程序,但它不会打开正确的活动,并生成以下日志.
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
Run Code Online (Sandbox Code Playgroud)
这条额外的线
Warning: Activity not started, its current task has been brought to the front
Run Code Online (Sandbox Code Playgroud)
我实际上也尝试过使用这个chrome意图的网站:
intent://dlhost/param#Intent;scheme=dlscheme;package=some.package.name;end
Run Code Online (Sandbox Code Playgroud)
它会表现得一样.
Mic*_*rla 12
在项目的清单文件中,您需要将跟随添加到主要活动中.
android:launchMode="singleTask"
Run Code Online (Sandbox Code Playgroud)
所以,在清单中,你会得到类似下面的内容:
<activity android:name="some.package.name.LaunchActivity"
android:launchMode="singleTask">
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>
Run Code Online (Sandbox Code Playgroud)
基本上它的作用是创建一个新任务,一个新实例将作为根任务推送到任务.但是,如果任何任务中存在任何活动实例,系统会通过onNewIntent()方法调用将意图路由到该活动实例.在此模式下,活动实例可以推送到同一任务.如果用户从当前活动中单击BACK键,系统将使用户返回上一个活动.
另一方面,singleTop
如果活动实例已经存在于当前任务的顶部并且系统将意图路由到此活动,则不会创建新实例,因为它将触发onNewIntent()方法而不是创建新对象.
更多信息可以在这里找到.
res*_*218 10
在项目的清单文件中,您需要将跟随添加到主要活动中.
android:launchMode="singleTask"
Run Code Online (Sandbox Code Playgroud)
并处理内部的深层链接 onNewIntent()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recipe);
onNewIntent(getIntent());
}
protected void onNewIntent(Intent intent) {
String action = intent.getAction();
String data = intent.getDataString();
if (Intent.ACTION_VIEW.equals(action) && data != null) {
String recipeId = data.substring(data.lastIndexOf("/") + 1);
Uri contentUri = RecipeContentProvider.CONTENT_URI.buildUpon()
.appendPath(recipeId).build();
showRecipe(contentUri);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10073 次 |
最近记录: |