【问题标题】:Launcher activity open two times using deeplinking启动器活动使用深度链接打开两次
【发布时间】:2016-12-08 16:17:29
【问题描述】:

事情是这样的:

我必须实现与应用程序启动器活动端点的深度链接。

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

        <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 之类的标签,但随后只启动了不良意图(默认启动器意图)。


我怎样才能使两个意图过滤器一次触发一个?

【问题讨论】:

  • 你能发布你实际解析深度链接的活动代码吗?
  • 这应该是无关紧要的,因为活动不能被创建两次......但我会过去部分代码表单 onCreate
  • 你是对的,对不起。请看答案

标签: android android-intent deep-linking


【解决方案1】:

所以,你有 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() 方法获得的深层链接并继续执行您想要的任何活动,这不会触发您的启动意图。

【讨论】:

  • 在我的情况下它不会解决问题。启动器意图仍将被触发。我想要实现的是在不需要时不触发启动器意图(当存在带有动作视图意图的深层链接时)
  • 我正在测试您的解决方案。它似乎工作。我创建了一个新活动来管理深层链接,然后完成()它。但是在应用程序启动时有一个图形错误,例如眨眼……我不能为此使用广播接收器吗? ://
  • hm,您是否删除了深度链接活动中的 setContentView()?
  • 我确实删除了它
猜你喜欢
  • 2015-06-12
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 1970-01-01
  • 2018-10-12
  • 2018-08-25
  • 2019-12-13
相关资源
最近更新 更多