Why do AndroidManifest.xml files have redundant android:label attributes? - android

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.

Related

Google Docs main activity: couldn't find address

I am developing a Huawei custom Theme. I was trying to change some Google apps (Documents, Sheets and Slides) icons. So I used as address their package name e.g. com.google.android.apps.docs.editors.slides
Since it didn't work, I tried with some activities, found in the manifest file, but no one worked yet. (for example com.google.android.apps.editors.homescreen.HomescreenActivity, which is the first one that appears when I open Slides);
So the question is:
is there a way to identify which is the main activity, nay, which is the activity who defines app icon?
Usually, the main activity declares the following intent filters (documentation) in order to indicate for the system that this activity is Main and is a launcher activity:
<activity android:name=".ActivityClassName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

App title is title of first activity?

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.

Change application's name without touching the default activity

I have an Android application with a default activity which is defined in the AndroidManifest.xml:
<application
android:label="NameOfMyApp"
...
<activity
android:name=".LoginActivity"
android:label="Login">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.rei0d.wop.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
It seems that android:label="NameOfMyApp" will be overwritten if there is an attribut android:label for the default activity.
So I want to change the application's name to something else than Login, NameOfMyApp for example, without changing the android:label of the Login activity. Is this possible? Or do I have to create a blanc activity as default activity which starts the Login activity?
Well, there are multiple possibilities to fix this issue, unfortunately some of them don’t work on all devices.
It seems like that the Launcher takes the application-name from the label of the "Entry Activity". You can prevent his by adding the following attribute to your intent-filer:
<intent-filter android:label="NameOfMyApp">
Unfortunately some Launchers may ignore this, so I wouldn’t go for this solution.
I would recommend you to change the title of your Login-Activity programatically. So first of all change the android:label value of your .LoginActivity to the name of your app.
In onCreate or somewhere else set the title (assuming that you’re using the ActionBar).
getActionBar().setTitle("Login");
Note: You should get the title from a strings-xml file of course

Is there a way to rename the android program shortcut on desktop?

In some modified version(for example, CM7), you can long press the shortcut to rename it.
But CM7 have some bugs now.
I would like to know is there a way I can do that? modify the database, change the programs code or resources is OK. Thanks.
You need to change AndroidManifest.xml file. You should find the activity that is launched by this icon and change android:label value there. This will change the icon name in Application Launcher and on Home Screen.
It should looks something like this:
<activity android:name=".HelloWorld" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The activity definition in AndroidManifest.xml should contain MAIN and LAUNCHER in its intent filter (otherwise the activity will not be visible in Application Launcher).

How to name Android Application

I have an Android App with 2 activities. I have the following in the AndroidManifest:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="false">
<activity android:name=".MyCellTracker" android:label="#string/activity1_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplaySuccess" android:label="#string/activity2_name"></activity>
The activities are properly named, yet the application is using the project name rather than the android:label (#string/app_name) I have given it. If I go to delete the application, then I see that it is named using the android:label. Why is the name that is displayed under the icon on the program launcher not using android:label in the application node?
This may not be the answer you're looking for, but you can set the activity title using setTitle(string title).
Set the title programmatically, and set the app title in the manifest.xml using the main activity's label.
According to that reference:
http://developer.android.com/guide/topics/manifest/activity-element.html#label
it is the label of the main activity. However if you don't set a label in the activity, the label of the application is taken.

Categories

Resources