28

I have reviewed the manifest for application, and under apps launcher it displays as Activity Name rather than its app name? Why is this. I have another application where when I install it, there are 5 entries one for each activity in the application when there should be just one name, that of the app? So when I go to launch it has 5 identically named apps in the launch list. These are named after the app but there is one for each activity. What could be the reason for this?

Androider
  • 21,125
  • 36
  • 99
  • 158

6 Answers6

45

The above accepted answer is wrong. It says,

the name comes from the android:label attribute on the application tag

That's not true. Take the following code for example.

<activity android:name="ApiDemos" android:label="@string/app_name">
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.DEFAULT" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity>

In this code, the app name that shows in the launcher is set by the android:label attribute in the activity tag not the application tag as the above accepted answer says.

To correct the above accepted response, the name shown under the icon in the launcher comes from the android:label attribute in the entry point activity's activity tag (the activity tag that contains the DEFAULT and LAUNCHER categories) unless you don't specify it there in which case it comes from the android:label attribute on the application tag.

Your first issue can be solved by changing the android:label attribute in your entry point activity's tag.

Patrick
  • 11,552
  • 7
  • 29
  • 41
  • 5
    What a strange behaviour. It would seem more logical to use the activity name for the activity, and the app name for the launcher. Do you see any sense in it working just how it does? – Luis Mendo Aug 17 '13 at 15:26
  • 3
    It's so app devs can have more than one launcher icon (and associated entry point activity) and are able to have separate names for each launcher icon. You can do this by including the following code in more than one activity tag in the manifest: ` ` and adding `android:label="@string/app_name"` to each activity tag. – Patrick Aug 20 '13 at 06:18
  • 2
    @Patrick so how can i put label for the entry activity seperated from application name? if i am willing to have only one main activity? – Kareem Elsayed Aug 18 '16 at 16:20
15

For the first issue, you should be aware that in absence of a label on the launching Activity the name comes from the default label set in the android:label attribute on the application tag:

<application android:name="ApiDemosApplication"
   android:label="@string/activity_sample_code"
   android:icon="@drawable/app_sample_code">

If the Activity has a label, that label will be used instead.

For the second issue, in the manifest, it is likely that all your activities specify an intent filter with an action of android.intent.category.LAUNCHER. For example:

<activity android:name="ApiDemos">
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.DEFAULT" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter>
</activity>

If you have such intent-filter tags on all activities, you should take out the intent filter tags on all but the Activity that you want to launch at startup. If this Activity has a label, it is the label that will be shown along with the launcher icon.

As of 2019/01/03 on API 27+, it appears that the first activity with the LAUNCHER category will be launched and its label will be associated with the app icon, so it may not be strictly necessary to remove all the redundant intent filters, but I'd do it anyway because it can lead to confusion.

Brian Cooley
  • 11,622
  • 4
  • 40
  • 39
  • 1
    Ok. So the without the label it will pick the name for an main activity. – Androider Mar 22 '11 at 20:54
  • Still seems like launchers entries should be for the app and not based on activities at all, but this was the problem – Androider Mar 22 '11 at 20:55
  • 1
    actual I do have an android label in the manifest I posted above?? – Androider Mar 22 '11 at 20:56
  • android:label="@string/app_name" – Androider Mar 22 '11 at 20:57
  • I see the problem I referenced string.xml when I was looking for strings.xml with s. So misspelled could not find it. – Androider Mar 22 '11 at 21:19
  • The LAUNCHER category is setting up the Activity that launches when you touch the icon in the Launcher. If there are multiple Activities that respond to the Intent (because of the category tags), the framework can't figure out what to launch and asks the user. – Brian Cooley Mar 22 '11 at 21:29
  • 1
    I had the same problem but fixed it by changing android:name in the that has and – richy Nov 19 '12 at 03:23
8

One way to have a different application name (the name that appears under the app icon) and a different name for the activity that is being launched when you tap on the app icon is to explicitly set a different string in the activity's onCreate() method, like this:

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // Do your thing
  // ... bla bla bla

  getActionBar().setTitle(R.string.activity_title);
}

Hope this helps!

Dan Borza
  • 3,419
  • 3
  • 22
  • 16
  • 2
    Use [`getSupportActionBar()`](https://stackoverflow.com/a/27712413/4084269) instead of `getActionBar()` if you are using the support library – Josselin Jun 18 '18 at 09:25
2

When you create an Activity via Eclipse, the property android:label inside your activity is automatically set to "@string/your_activity_name" in the AndroidManifest.xml. Adding the intent filter to provide a launcher for this activity, your launcher gets the same label as your Activities android:label.

If you want to label the launcher with your application name, you should change the Activities android:label to something like "@string/app_name".

stefank
  • 101
  • 3
1

As if you want to place a image view in the place of toolbar title. You have to update the label of particular activity in the android manifest as android:label=""; by doing this your activity name won't gets displayed in the toolbar after the image view and please use the following code for setting image view along with navigation icon and no toolbar title.

try {
    Toolbar  toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle("");
    if (getSupportActionBar() != null)
        getSupportActionBar().setIcon(R.drawable.header_image_wt);
} catch (Exception e) {
    e.getMessage();
}
Shaido
  • 27,497
  • 23
  • 70
  • 73
0

Running Android version 4.1.2 the name of the application will be "static" with respect to the label defined in the activity set as main launcher and not overridden in any intent filters

joacar
  • 891
  • 11
  • 28