Click here to Skip to main content
15,887,746 members
Articles / Mobile Apps / Android
Tip/Trick

How to Name Your Android APP Correctly

Rate me:
Please Sign up or sign in to vote.
4.93/5 (4 votes)
12 Feb 2015CPOL 17.3K   10   4
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
<?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
<?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
<?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. :)

This article was originally posted at http://blog.csdn.net/lamp_zy/article/details/7878979

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student Tsinghua University
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerTo answer .... Pin
Ankit Torino (Dom)13-Feb-15 17:20
Ankit Torino (Dom)13-Feb-15 17:20 
GeneralRe: To answer .... Pin
David Fan Quan13-Feb-15 18:27
David Fan Quan13-Feb-15 18:27 
GeneralRe: To answer .... Pin
Ankit Torino (Dom)13-Feb-15 18:30
Ankit Torino (Dom)13-Feb-15 18:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.