03 September 2012

Android labeling issue

I've recently installed new ADT for Eclipse with a new Project Wizzard and realized that in Android launcher my application name has an unusual value. Here is a small research on this theme.



Problem:
Lets assume that the name of our application is "Our Application" and the title of the main activity (which is launched by Android launcher) is "AcMain". Thus, when I deploy my project on a device in the launcher I see "AcMain" instead of "Our Application":


Research: 
At first I thought that my manifest file is misconfigured. In my case, it looks in the following way:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ourapplication"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".AcMain"
            android:label="@string/title_activity_ac_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

strings.xml looks in the following way:
<resources>

    <string name="app_name">Our application</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_ac_main">AcMain</string>

</resources>

Thus, I understood that instead of using app_name label of application the launcher uses title_activity_ac_main label. I started to read the documentation about label tag of <activity> and <application> and found the label in the application tag is redefined by the label in the activity tag.
I also have some projects that have been created with older versions of ADT and found that before ADT generated labels for activities equal to app_name:
<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".activity.AcMain"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Thus, all activities have the same label.

Solution:
After this small research I've decided to look at the Project Wizzard carefully and find the following:


In the "Title" field you can specify the name of the Activity and in case if this activity is a main activity this label will be used in the launcher.

But to my point of view this is not the right solution because I want the application label to be used in the launcher. I found that intent-filter can also have label and in case of launcher intent-filter this label is used to in the launcher. I submitted an enhancement to Android tools project but before it is implemented the following solution can be used:
<activity
            android:name=".AcMain"
            android:label="@string/title_activity_ac_main" >
            <intent-filter android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

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

1 comment:

  1. Bravo and thank you. I was looking a long time for a solution of this problem.

    ReplyDelete