安装为多个图标的 Android 应用活动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3527263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:36:44  来源:igfitidea点击:

Android App activities installed as multiple icons

android

提问by Aaron C

My Android App has 2 activities. A login screen and a search screen. When I deploy the app on emulator or on my device, I see 2 icons for same app. When I click on icon 1 it opens screen 1 (login screen) and When I click on icon 2 it opens screen 2 (search screen). By logic when I login it should show the search screen. Not sure when I'm making the mistake.

我的 Android 应用程序有 2 个活动。登录屏幕和搜索屏幕。当我在模拟器或我的设备上部署应用程序时,我看到同一个应用程序的 2 个图标。当我单击图标 1 时,它会打开屏幕 1(登录屏幕),当我单击图标 2 时,它会打开屏幕 2(搜索屏幕)。按逻辑,当我登录时,它应该显示搜索屏幕。不知道什么时候我犯了错误。

回答by Aaron C

Your manifest file should only have this line in the activity you want to have an icon:

您的清单文件应该只在您想要拥有图标的活动中包含这一行:

<category android:name="android.intent.category.MAIN" />

Based on your description, it sounds like both activities have this line.

根据您的描述,听起来这两个活动都有这条线。

回答by Megha

In your mainfest file when you have following tag in two different activities tags at the time, Android app seems to be installed twice.

在您的 mainfest 文件中,当您在两个不同的活动标签中有以下标签时,Android 应用程序似乎安装了两次。

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>    

回答by marienke

The comment made by @Adrian C on his answer solved our problem.

@Adrian C 对他的回答发表的评论解决了我们的问题。

The manifest file of our main application had only one intent-filtertag specifying only one activity as the launcher activity for the application.

我们主应用程序的清单文件只有一个intent-filter标签,指定了一个活动作为应用程序的启动器活动。

So I had to look deeper...

所以我不得不更深入地看...

We included library projects (luckily written by us) and the manifest file of one of the library projects had an intent-filtertag on its activity specifying that activity as the launcher activity.

我们包含了库项目(幸运的是我们编写的),并且其中一个库项目的清单文件intent-filter在其活动上有一个标签,指定该活动为启动器活动。

When we then included that library project in our main application (which has its own intent-filterspecifying a launcher activity), the complete source code saw two intent-filtertags specifying two activities as launcher activities and therefore two application icons were created.

当我们将该库项目包含在我们的主应用程序中时(它有自己intent-filter指定的启动器活动),完整的源代码看到两个intent-filter标记将两个活动指定为启动器活动,因此创建了两个应用程序图标。

When we removed the intent-filterspecifying a launcher activity in the library project, the second app launcher icon disappeared.

当我们intent-filter在库项目中删除指定启动器活动时,第二个应用启动器图标消失了。