开发者

Different activity title in different intent actions

I have one activity and three intet filters, each with different label set on, (AndroidManifiest.xml below)

    <activity android:name=".activities.RecordActivity">
        <int开发者_如何学编程ent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="com.keitai.enigma.OPEN_RECORD" />
        </intent-filter>
        <intent-filter android:label="@string/newRecord">
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="com.keitai.enigma.NEW_RECORD" />
        </intent-filter>
        <intent-filter android:label="@string/editRecord">
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="com.keitai.enigma.EDIT_RECORD" />
        </intent-filter>
    </activity>

But activity title is not changing to label set in intent filter :( Activity always contains application label.

What I'm donig wrong?


Are you sure you don't have code that is setting the title explicitly?

Are you sure that the OPEN_RECORD intent isn't the one being triggered every time?

Have you tried debugging by making sure everything has a distinct label (application, activity, each intent-filter) and seeing what happens?

I agree with you that what you expected to happen is what the docs say should happen. But it seems like the default <application> label is being used regardless. I'm afraid if one of the above ideas doesn't help, then I'm out of ideas. I might try it myself later on my system to see if it happens for me.


http://developer.android.com/guide/topics/manifest/intent-filter-element.html#label

android:label

A user-readable label for the parent component. This label, rather than the one set by the parent component, is used when the component is presented to the user as having the capability described by the filter.

...

The default value is the label set by the parent component. If the parent does not specify a label, the default is the label set by the element's label attribute.


http://developer.android.com/guide/topics/manifest/manifest-intro.html#iconlabel

Icons and Labels

...

In every case, the icon and label set in a containing element become the default icon and label settings for all of the container's subelements. Thus, the icon and label set in the element are the default icon and label for each of the application's components. Similarly, the icon and label set for a component — for example, an element — are the default settings for each of the component's elements. If an element sets a label, but an activity and its intent filter do not, the application label is treated as the label for both the activity and the intent filter.

...


You use intents usually to pass information between activities, apps or services (just few examples). My understanding is, that you want to change your title of one activity depending on e.g. if a button is pressed. Therefore you need to set simply in your activity
this.setTitle("YOUR ACTIVITY NAME");
In case you want this to happen after a button click, put it into the listener of the corresponding button.


Actually, from your example I'd suggest that you use separate activities (which can specify labels that are shown as titles!). In Android, one activity usually corresponds to one use case - so if OPEN_RECORD shows a dialog where the user can select a record and EDIT_RECORD allows to edit a record, than you would usually have two different activities.

Have a look at the notepad tutorial for an example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜