65.9K
CodeProject is changing. Read more.
Home

How to Name Your Android APP Correctly

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.93/5 (4 votes)

Feb 12, 2015

CPOL
viewsIcon

17930

Are you sure you really know how to name your app? If you know Activity's label has higher priority than Application's label, you'll get it.

Background

Today, I'm frustrated by my app's name. I created an app to test a third-party library, including an Application & Activity generated by Android Studio.

AndroidManifest.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.aiesec.experience.expa" >

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

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

strings.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">EXPA</string>
    <string name="title_activity_main">MainActivity</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>

</resources>

But, the result is...

That is not what I want. What's happened?

Explanation

Translated from: http://blog.csdn.net/lamp_zy/article/details/7878979

Activity & Application both have an attribute called android:label, but Activity's has higher priority than Application's. It means that if these two are both set, Application's will not work.

One case is that Application's label is set but Activities' aren't. In this case, the label will be displayed under app's icon and all of Activities' title will be set as the label's value.

Another case is that Application's & MainActivity's label are set, leave other Activities alone. This time app's name & MainActivity's title are the same as MainActivity's label. While other Activities don't have a label will follow Application's label.

Solution

That'll be very easy. Just use @string/app_name instead of @string/title_activity_main as MainActivity's label. As the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.aiesec.experience.expa" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            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>
</manifest>

That's it. Thanks for reading. :)