Android Application creating two launcher icons

你说的曾经没有我的故事 提交于 2019-12-07 01:07:24

问题


I am having a very confusing problem with an application I have been working on for some time. Suddenly, when running my application, I found an immediate force close upon launch.

Upon further investigation, I found two launcher icons in my launcher. One of which will either resume the application if it is running or force close if it is not running. The second will behave as normal - launches the application normally and resumes normally.

I am very confused, as I was not doing anything (that I can think of) to cause this problem. I was not changing anything whatsoever in the manifest and just implementing a few new methods to change colors in my app faster.

These problems persist identically in all my emulators and devices whether I turn off the phone, manually kill the app or uninstall/reinstall the app. A simple ctrl+z did not work. To clarify - all I would like is to go back to have one launcher icon to launch my application normally (nothing special goes on at all).

Update:

I am now presented with an immediate force close on launching from either icon. I did find code within two activities within my Manifest displaying and changing the second line from .LAUNCHER to .DEFAULT did fix my original problem. However, I am now always presented with an immediate force close...there are now problems (that I can see) within my originally launcher activity...I am having a lot of trouble attempting to fix this (have no idea what to do) and am starting to become VERY worried!

Update 2:

I found my problems and I thank you guys for all your help! I actually had two separate and unrelated problems that occurred at the same time. Number one - two icons in my launcher: caused because I had two activities with a

回答1:


two activities have

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

remove second one




回答2:


Actually Android Launcher displays all activities with category LAUNCHER not applications.

If your application contains more than 1 activity, you have to use action MAIN and category LAUNCHER for your default activity (initial screen) of application only, not for all activities you used in application. If you put same for every activity in application it will be displayed in Android Launcher.

Please read about the Intent Actions and Categories, you will understood.




回答3:


Well , I was facing same problem. Problem was when I RUN app, it was creating two icons one with name MyApp and other with SplashActivity. When I was attempting to uninstall SplashActivity (named app), in Confirmation message it was saying

SplashActivity is part of MyApp , sure you want to uninstall?

After looking at some references, concluded that when we put

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

under any activity, android thinks that this is the MAIN entry point of App. And creates an launcher icon for that activity. but name was kept as acivityName.

So Finally by changing Activity tag of SplashActivity from

 <activity
    android:name=".activities.SplashActivity"
    android:label="@string/title_activity_splash"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
 </activity>

to

<activity
    android:name=".activities.SplashActivity"
    android:label="@string/app_name"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

It solved my issue of multiple icons and launcher icon name as activityName instead of appName.




回答4:


In my case, helped somethning like that

The old one lines from the manifest file

Splash screen activity

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

Main Activity

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

And the new one

Splash screen activity

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

Main Activity

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

Just remove in Main Activity this line below

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

And that's it !




回答5:


in AndroidMenifest.xml file you have to remove two or three android name i.e

<activity
    android:name=".SplashScreen"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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


来源:https://stackoverflow.com/questions/8697943/android-application-creating-two-launcher-icons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!