Unable to set different icon / shortcut for application and launch activity from manifest

I know this question has been asked before, but in all of them the answer is to set it from the onCreate method. I DO NOT want to do this in my onCreate method, so I did this with my manifest file, but to no avail: -

<application android:allowBackup="true" android:icon="@drawable/ic_launcher_screen" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light" > <activity android:name="com.iws.unify.HomeScreen" android:label="@string/nullstring" android:icon="@drawable/ic_launcher" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

For whatever reason, any icon / label that I set in action overrides this in the application tag, which is so annoying. Please help.

+4
source share
4 answers

I had the same problem, I decided to use a very strange but simple solution.

1- create a new action and name it LauncherActivity (set the icon and label of this action that you want to display as the application icon / label)

2- set this action as the main and starting application of your application. (remove the <intent-filter> from your HomeScreen activity)

3- set the theme of this action android:theme="@android:style/Theme.Translucent"

4- now do nothing in your LauncherActivity onCreate() , just start the HomeScreen action using the intent and complete this action.

 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, HomeScreen.class); startActivity(intent); finish(); } 

finish () is required, so when you click the back button in HomeScreen, the application closes.

your icon and shortcut for your application will now be different from the HomeScreen icon and label

your manifest should look like this:

 <application android:allowBackup="true" android:theme="@android:style/Theme.Holo.Light" > <activity android:name="com.iws.unify.HomeScreen" android:label="@string/nullstring" android:icon="@drawable/ic_launcher" > </activity> <activity android:name="com.iws.unify.LauncherActivity" android:icon="@drawable/ic_launcher_screen" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

+4
source

If you only need to have an action bar icon different from the application icon, you can override it with the "android: logo" attribute for this:

  <activity android:name="com.iws.unify.HomeScreen" android:label="@string/nullstring" android:logo="@drawable/ic_launcher"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 
+14
source

Answer:

Remove the icon in Android activity.

Additional Information:

The main activity with an activity launcher will be considered during the execution of Android.

For example: IF you declare the following code in two actions "a" and "b" .:

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

Then your application will have two launch icons "a" and "b".

+1
source

You can also use an "activity alias":

 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light"> <activity android:name="com.iws.unify.HomeScreen" android:label="@string/nullstring" android:exported="true" /> <activity-alias android:name=".LaucherActivityAlias" android:targetActivity="com.iws.unity.HomeScreen" android:icon="@drawable/ic_launcher_screen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias> </application> 

The "playstore" icon will be specified in the node application, so you can also do this if you need to:

 <application android:allowBackup="true" android:icon="@drawable/ic_launcher_screen" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light"> <activity android:name="com.iws.unify.HomeScreen" android:label="@string/nullstring" android:icon="@drawable/ic_launcher" android:exported="true" /> <activity-alias android:name=".LaucherActivityAlias" android:targetActivity="com.iws.unity.HomeScreen" android:icon="@drawable/ic_launcher_screen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity-alias> </application> 
0
source

Source: https://habr.com/ru/post/1487047/


All Articles