【Android开发那点破事】Android调试安装出现2个或2个以上图标

前些日子给我们的APP添加了启动画面功能,这个在前面已经说过了: 【Android开发那点破事】打开APP加载页面实现

今天在用真机调试的时候,发现app安装到手机上出现了2个图标。

这里先将解决方法贴出来,后面再简单分析下为什么会出现2个图标。

解决方案:

在AndroidManifest.xml, CTRL+F中找到所有包含:

category android:name="android.intent.category.LAUNCHER"

把多余的删除,只保留你APP启动时的第一个activity中的。比如我这里只保留APP加载页面的配置:

<!-- startup page -->
<activity android:name="com.withiter.quhao.activity.LaunchActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:label="@string/app_name">
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>
		<!-- startup page -->

我们来分析下为什么会这样:

首先看下android官方的一些描述:

  • { action=android.app.action.MAIN } matches all of the activities that can be used as top-level entry points into an application.

  • { action=android.app.action.MAIN, category=android.app.category.LAUNCHER } is the actual intent used by the Launcher to populate its top-level list.

  • { action=android.intent.action.VIEW data=content://com.google.provider.NotePad/notes } displays a list of all the notes under "content://com.google.provider.NotePad/notes", which the user can browse through and see the details on.

  • { action=android.app.action.PICK data=content://com.google.provider.NotePad/notes } provides a list of the notes under "content://com.google.provider.NotePad/notes", from which the user can pick a note whose data URL is returned back to the caller.

  • { action=android.app.action.GET_CONTENT type=vnd.android.cursor.item/vnd.google.note } is similar to the pick action, but allows the caller to specify the kind of data they want back so that the system can find the appropriate activity to pick something of that data type.

  • { action=android.app.action.MAIN, category=android.app.category.LAUNCHER } is the actual intent used by the Launcher to populate its top-level list.这个翻译过来就是添加了{ action=android.app.action.MAIN, category=android.app.category.LAUNCHER } 的activity 是在程序启动的列表中的。所以如果定义多个LAUNCHER,就会出现多个APP图标。


  • 最后我们来总结下:
    一个应用程序可以有多个Activity,每个Activity是同级别的,那么在启动程序时,最先启动哪个Activity呢?有些程序可能需要显示在 程序列表里,有些不需要。怎么定义呢?android.intent.action.MAIN决定应用程序最先启动的Activity ,是程序的入口android.intent.category.LAUNCHER决定应用程序是否显示在程序列表里。因为你的程序可能有很多个activity只要xml配置文件中有这么一个intent-filter,而且里面有这个launcher,那么这个activity就是点击程序时最先运行的那个activity。现在你只有一个activity,那么加不加就没有关系了。用于模拟器启动时设置为默认打开为的activity。


    好了今天这个破事就到这里,其实android开发就这么点破事。关于其他破事,见专栏:

    更多Android开发的破事,请看专栏:《Android开发那点破事》


  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值