启动器活动使用深层链接打开两次

时间:2016-12-08 16:17:30

标签: android android-intent deep-linking

事情就是这样:

我必须使用作为应用程序启动器活动的终点实现深层链接。

所以在清单中,在启动器活动标签中有:

        <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="scheme" />
        </intent-filter>
来自活动onCreate方法的

片段:

        if (getIntent() != null) {
            // Url scheme
            if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
                // Process the deelink
            } else {
                // Do something else
            }
        }

问题:活动打开两次,一次具有良好意图(ACTION_VIEW),另一次没有

我尝试使用像single_top,single_task,single_instance这样的标签但是只启动了不良意图(默认的启动器意图)。

如何才能使两个intent过滤器一次触发一次?

1 个答案:

答案 0 :(得分:0)

所以,你有2 intent-filters。我不知道这是否属实,但是,我处理深层链接的方式是下一步:

创建新活动

DeepLinkActivity.class

OnCreate()方法,不设置内容视图,此活动仅用于解析您要解析的深层链接。从那里,您可以创建意图并将数据传递给您要打开的下一个活动。希望它能以任何方式帮助。

<强> 修改

在您的情况下,创建新的活动DeepLinkActivity,添加他的意图过滤器

<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="scheme" />
    </intent-filter>

现在,不要为该活动设置内容视图,解析您从getIntent()方法获得的深层链接并继续进行您想要的任何活动,这不会触发您的开始意图。