简体   繁体   English

为什么我们会得到这些“无效”意图?

[英]Why do we get these “invalid” intents?

We have an app with an Activity that can be started in two ways: 我们有一个带有Activity的应用程序,可以通过两种方式启动:

  • From another Activity - always with some extra data filled in 来自另一个活动 - 总是填写一些额外的数据
  • From deep linking 从深层链接

As far as I can see this is always working just fine. 据我所知,这总是很好。 We either get the Intent.ACTION_VIEW with a data URI, or we get some string extras. 我们要么使用数据URI获取Intent.ACTION_VIEW ,要么获得一些字符串附加功能。

However, we have a very few instances where action is Intent.ACTION_MAIN and there are no extra data. 但是,我们有很少的实例,其中操作是Intent.ACTION_MAIN ,并且没有额外的数据。

The toString() of the Intent is as follows (class name changed): Intent的toString()如下(类名更改):

Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10400000 cmp=com.example.OurActivity }

Intent.getExtras() returns null, Intent.getDataString() returns null. Intent.getExtras()返回null, Intent.getDataString()返回null。

In which cases can this happen? 在哪些情况下会发生这种情况? Why is the category for the Activity Intent.CATEGORY_LAUNCHER ? 为什么Activity Intent.CATEGORY_LAUNCHER的类别? How can we get the data needed to show the user the right contents? 我们如何获得向用户显示正确内容所需的数据?

launchMode is not specified for the Activity. 未为活动指定launchMode The only IntentFilter in AndroidManifest.xml is for the deep linking (and not the launcher category). AndroidManifest.xml唯一的IntentFilter用于深层链接(而不是启动器类别)。

The issue happens on Android 4-6 on a wide range of devices. 问题发生在Android 4-6的各种设备上。

Edit: Forgot to mention the flags: 编辑:忘了提旗子:

As the print out suggests the flags for the Intent are FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_BROUGHT_TO_FRONT . 由于打印输出表明Intent的标志是FLAG_ACTIVITY_NEW_TASKFLAG_ACTIVITY_BROUGHT_TO_FRONT I suppose that could be relevant here. 我想这可能与此相关。

I believe, I nailed it: 我相信,我钉了它:

There're launchers, like Nova Launcher which allows users to start with any of app's Activities , instead of the normal flow: Nova Launcher这样的发射器允许用户从任何应用程序的Activities ,而不是正常的流程:

在此输入图像描述

For example , you can add a shortcut on your desktop to start Gmail client with Account setup Activity. 例如 ,您可以在桌面上添加快捷方式,以使用帐户设置活动启动Gmail客户端。

And in this case, Activity is being started with empty Extras and technically it becomes a launcher's Activity . 在这种情况下,Activity正在使用空Extras启动,从技术上讲它将成为启动器的Activity

Now that AndroidManifest.xml is manipulated by the build system, it often happens that libraries that you include also add things to the manifest, which I suspect may be happening here. 既然AndroidManifest.xml是由构建系统操纵的,那么你所包含的库经常会在清单中添加内容,我怀疑这可能会在这里发生。

Although you state that there is only one IntentFilter in the manifest, have you actually checked the installed app to see what its manifest says (rather than relying on what you think you put in your source code)? 虽然您声明清单中只有一个IntentFilter,您是否实际检查了已安装的应用程序以查看其清单所显示的内容(而不是依赖于您认为自己在源代码中添加的内容)?

Various apps are available in the Play Store to show you the manifest of an installed app - including App Detective (which I wrote). Play商店中提供了各种应用程序,以显示已安装应用程序的清单 - 包括App Detective(我写的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM