Because your app can define more than one activity that shows up in the launcher. All activities that have this type of intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Will appear in the launcher, each with its own label. The fact that if you don't define a label on your activity, it's inherited from the application is basically a commodity.
Also, every activity has its own android:icon
(which, again, is inherited from <application>
for commodity). With this property your two launcher entries can have not only different labels, but different icons as well.
On a more general note, even "non-main" activities can handle certain types of events, and in these cases their labels and icons are relevant. For example, if one of your activities (doesn't matter which one) handles ACTION_SEND
intents (like most sharing apps do -- see Facebook, Twitter, ...), then whenever the user presses a "Share" button in any application, a list of applications that can complete that certain activity is displayed to the user (in this case these applications could be Facebook, Twitter and your app). This list will contain an icon and a label (i.e. Facebook). Your entry's display will be dictated by the android:icon
and android:label
attributes defined by your receiving <activity>
, and only if it doesn't define them they'll be taken from your <application>
.
This allows you to have an entry such as "Share via MyApp" without modifying your application's name. Or, if your application also has an activity that handles ACTION_VIEW
, that activity could have, for example, the label "View in MyApp".
Digging even deeper, <intent-filter>
elements can have their own label and icon. Basically, Android chooses the icon and label to display like this:
- If the
<intent-filter>
has it, pick that, stop.
- If the
<activity>
has it, pick that, stop.
- Pick the one in
<application>
.
This is helpful in two situations:
- You don't want to change your activity's label / icon: maybe you want to use those in other places such as the title bar (and you don't want your title bar to say "Share via MyApp")
- You have activities with multiple intent filters. For example, you could handle both
ACTION_SEND
and ACTION_VIEW
intents in the same activity. In this case, you'd have two intent filters set for that activity with the labels "Share via MyApp" and "View in MyApp".
I hope I've made myself clear, these are very basic things that can be pretty hard to grasp at first, but that provide great flexibility in building apps and integrating them with the Android system and/or other apps.
Another thing to note is that you can easily have an application that doesn't have any entries in the launcher (by not having any activity with the intent filter mentioned above). These are perfectly valid apps and it's good practice when creating Service-only apps (such as widgets).