JudasMoses
JudasMoses

Reputation: 398

The use of the android:value in metadata -- Android

I am confused with the use of values in metadata. When I am giving the metadata of an activity, what does it do with the android:value I give it. What does this value do.

Example

`        <activity
            android:name=".SecondActivity"
            android:label="@string/activity2_name"
            android:parentActivityName=".MainActivity">
            <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".SecondActivity" />
        </activity>`

Yes I have looked at the documentation for meta-data on https://developer.android.com/guide/topics/manifest/meta-data-element. The description

The value assigned to the item.

Does not make sense to me. Can anyone please explain the use of the android:value in metadata to me or rules on what to data to give it.

Why does it give me errors when I do not have a value in the manifest such as. Failed to finalize session : INSTALL_PARSE_FAILED_MANIFEST_MALFORMED:... <meta-data> requires an android:value or android:resource attribute

NOTE: I am not looking for a answer specific to my code for that error/ question. Just a general answer if there is one.

Thank you :)

Upvotes: 0

Views: 2735

Answers (2)

JudasMoses
JudasMoses

Reputation: 398

@navylover 's answer is correct and helpful however I wanted to expand on it by saying. The value of the parent activity can be found by doing "package name"."application name"."activity name"

These can be found under the build.gradle file. An example of what the code will look like is on: https://developer.android.com/studio/build/application-id.

Upvotes: 0

navylover
navylover

Reputation: 13539

meta-data is a name-value pair, so the meaning of android:value is dependent on android:name. For your example:

<meta-data
   android:name="android.support.PARENT_ACTIVITY" //the activity has a parent activity 
   android:value=".SecondActivity" //the parent activity name is SecondActivity
/>

and what's parent Activity and how to use it ,you could ref https://developer.android.com/training/implementing-navigation/ancestral#top_of_page

if you only provides android:name but no android:value, its pointless.

Upvotes: 1

Related Questions