Chintan Trivedi
Chintan Trivedi

Reputation: 748

Cannot set different icon/label to application and launcher activity from manifest

I know this question has been asked before but in all of them the answer is to set it from onCreate method of activity. I DO NOT want to do this in my onCreate method, so I did this to 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 some reason whatever icon/label I set in activity overrides that in application tag which is so annoying. Please help.

Upvotes: 4

Views: 7095

Answers (4)

Mindfield Studio
Mindfield Studio

Reputation: 21

You can also use "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>

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

<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>

Upvotes: 0

Eugene
Eugene

Reputation: 165

If all you need is to have an activity action bar icon different from application icon, you can override it using "android:logo" attribute for that:

    <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>

Upvotes: 15

Tarek K. Ajaj
Tarek K. Ajaj

Reputation: 2507

I had the same problem, i solved using a Very weird but simple solution.

1- create a new activity and call it LauncherActivity.(set the icon and label of this activity what you want to be displayed as the application icon/label)

2- set this activity as the main & launcher activity of your app.(remove the <intent-filter> tag from your HomeScreen activity)

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

4- now in your LauncherActivity onCreate() don't do anything just start the HomeScreen activity using an intent and finish this activity.

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

finish() is required so when you press the back button in your HomeScreen the app closes.

now your app icon and label will be different from your HomeScreen Icon and label

your manifest should look like:

<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>

Upvotes: 4

amalBit
amalBit

Reputation: 12191

Answer:

Remove the icon in the android activity.

Extra info:

The main activity with the activity launcher will be considered by android runtime.

For example: IF you declare the following code in two activity "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 launcher icons "a" and "b".

Upvotes: 1

Related Questions