Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 373
Chintan Trivedi Avatar asked Dec 01 '22 03:12

Chintan Trivedi


2 Answers

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>
like image 147
Eugene Avatar answered Dec 05 '22 01:12

Eugene


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>

like image 20
Tarek K. Ajaj Avatar answered Dec 05 '22 01:12

Tarek K. Ajaj