I wanted to start a different activity from my app first, so I moved:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This led to an odd (but interesting problem), the name of my app (shown on home screen) has completely changed to the name of the activity that I am calling first. The thing is, I already have the name of the app declared up in the application tag:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="This should be the title, right?"
android:theme="#style/AppTheme" >
But the activity that is starting first is still the name of my app now. I have researched this thoroughly, but the only results were about how to change the name of your app,(example) which is like this:
android:label="This should be the title, right?"
But that's the strange part, as I already have that set, **yet ** the name of the app is still the name of the activity that is launching first. I would love to understand why that is happening, and how to fix this unexpected issue.
Thanks for the expert advice,
Rich
Here is my entire manifest:
https://gist.github.com/anonymous/12cd29ad7ea9b2206a2b
The caption used for the launcher icon can be driven by:
a label on the <intent-filter>, which you don't have
a label on the <activity>
a label on the <application>
So, if you have an android:label attribute on the <activity> that now has your MAIN/LAUNCHER <intent-filter>, confirm that it is what you want.
Also, home screen launchers can get a little weird at times, due to caching and such, and so a reboot of the device or emulator may be necessary.
The launcher icon will use the label of whatever activity the launcher intent-filter is in. If you want to change the title displayed in the action bar, you can call setTitle() on your Activity at runtime.
Related
This question already has answers here:
How to set different label for launcher rather than activity title?
(8 answers)
Closed 10 years ago.
So I've got an Android App with an generated Login Screen (the one you can directly create from Eclipse). That's working.
The problem is this:
I've set the Login screen to be the Launcher activity. This works. Unfortunately the App is then called as the label parameter of the login activity. Meaning the android:label value of the application is simply ignored.
Here's my code as my question sounds quite vague:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" <!-- the app name i want it to have -->
android:theme="#style/AppTheme" >
<activity
android:name="com.test.testytest.MainActivity"
android:configChanges="orientation"
android:label="#string/app_name" >
</activity>
<!-- some more activities -->
<activity
android:name="com.test.testytest.LoginActivity"
android:label="#string/title_activity_login" <!-- the name the app is called in the drawer etc. -->
android:windowSoftInputMode="adjustResize|stateVisible" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
strings.xml:
<string name="app_name">Testy Test!</string>
strings_activity_login:
<string name="title_activity_login">Sign in</string>
When I change the string of the Login activity to app_name, the name of the app changes, too. But I'm quite sure that the app should be called as defined in android:label in
Hope you can help me or point me to my mistake (maybe I'm just missing a little detail).
A little Edit: I don't want to change the label of my Login activity as it should remain "Login". And it also should stay the first activity to be called. But the App Name in the drawer should be the one defined in .
Thanks to Geobits:
Here's the solution How to set different label for launcher rather than activity title?
Solution found!
Apparently the "intent-filter" can have a label attribute. If it's absent
the label is inherited from the parent component (either Activity or
Application). So using this, you can set a label for the launcher
icon, while still having the Activity with it's own title.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
android:label="#string/title_home_activity"
android:icon="#drawable/icon">
I have a requirement that the title bar label on my launcher activity be different from the actual launcher label. This seems to work fine in the general case, however, I have a confirmed report from a user that their launcher label has changed over time to be the activity label. Here's an example:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/activity_title"
android:name="MyActivity" >
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Upon initial install, everything is correct. The launcher label shows up as the app_name string. When you launch the app the activity label is the activity_title string. However at some point the user opens up their app list and instead of seeing the app_name string for my app, they see the activity_title string.
They have installed multiple times and this seems to happen every time. Has anyone else seen this behavior and know of a way to resolve it?
EDIT:
After some more testing I figured out how to repro this every time with the manifest given above. If I install the app, then put a shortcut on the home screen and restart the emulator or device, then when it comes back up the shortcut has been renamed. The app in the app list is still correctly named. Weird stuff.
The DevGuide on the application element's android:label:
A user-readable label for the application as a whole, and a default label for each of the application's components.
Yet, there's a world of example manifests that have the form
<application ... android:label="#string/app_name">
<activity ... android:label="#string/app_name"> ... </activity>
<activity ... android:label="#string/app_name"> ... </activity>
...
</application>
Every single Android book I have does this, including the Commonsware books. A glance through the SDK examples shows that ContactManager does this, but not Snake or Lunar Lander.
Is there some historical reason for the attribute to be duplicated like this? Or is it, like Eclipse's stub comments that people leave in post-stub code (and book examples, in one case), or like the duplicate labels in my own imitative manifests, just something that people don't think about?
i think the activity tag with the attribute android:label is not necessary, except you want make the activity the title different with the application label, you can use your own label. the default should be as same as the application label.
A single App can have more than on icon in the Android Launcher as each icon can map to a single activity. A activity with below intent filter will be show as a standalone icon in launcher
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The value of android:label will be shown as the name under that icon in lancher
No AndroidManifest.xml of the API 2 (Android 1.1) SDK samples has this redundancy. I conclude that it was never necessary, and that it's a (harmless) example of cargo-cult programming.
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?
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.
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.
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!
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".
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();
}
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
In my manifest file, I have given the application name as MyApp and the name of the starting activity as Main Menu.
<application android:theme="#style/theme" android:icon="#drawable/myicon" android:label="#string/app_name">
<activity android:name=".MainMenu"
android:label="#string/mainmenu_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I see the app icon in the default menu screen of android, the name shown is Main Menu. Why is MyApp not the name shown for the app?
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).
If android:label is set for activity then its value is taken. It it is omitted for activity then the android:label attribute set on application is taken instead.
You simply cannot have different labels for activity and for application as your application has one launcher for your activity with the label you set it to have. I'm not quite sure I totally understand what you are trying to achieve tho.
In the manifest, remove the android:label attribute on the launch activity. Then the activity will inherit the name specified in the application's android:label.