<meta-data>

syntax:
<meta-data android:name="string"
           android:resource="resource specification"
           android:value="string" />
contained in:
<activity>
<activity-alias>
<service>
<receiver>
description:
A name-value pair for an item of additional, arbitrary data that can be supplied to the parent component. A component element can contain any number of <meta-data> subelements. The values from all of them are collected in a single Bundle object and made available to the component as the PackageItemInfo.metaData field.

Ordinary values are specified through the value attribute. However, to assign a resource ID as the value, use the resource attribute instead. For example, the following code assigns whatever value is stored in the @string/kangaroo resource to the "zoo" name:

<meta-data android:name="zoo" android:value="@string/kangaroo" />

On the other hand, using the resource attribute would assign "zoo" the numeric ID of the resource, not the value stored in the resource:

<meta-data android:name="zoo" android:resource="@string/kangaroo" />

It is highly recommended that you avoid supplying related data as multiple separate <meta-data> entries. Instead, if you have complex data to associate with a component, store it as a resource and use the resource attribute to inform the component of its ID.

부모 컴포넌트에 제공될 수 있고 추가적이고 임의의 데이터 아이템에 대한 이름-값 한 쌍name-value pair. 컴포넌트 엘리먼트는 임의의 개수의 <meta-data> 서브엘리먼트를 포함할 수 있다. 그것들 모두의 값들은 하나의 번들Bundle 오브젝트로 모아지고, PackageItemInfo.metaData 필드로써 컴포넌트에서 사용가능해진다.

보통 값들은 value 애트리뷰트를 통해 지정되어진다. 하지만 리소스 ID에 값을 할당하기 위해 리소스 애트리뷰트를 대신 사용하라. 예를 들어 다음의 코드는 “zoo” 이름에 @string/kangaroo 리소스 안에서 저장된 임의의 값을 지정한다.

<meta-data android:name="zoo" android:value="@string/kangaroo" />

반면에, 리소스 애트리뷰트를 사용하는 것은 “zoo” 에 리소스 안에 저장된 값이 아니라 리소스의 숫자 ID를 할당할 것이다.

<meta-data android:name="zoo" android:resource="@string/kangaroo" />

여러분이 여러 개의 별도의 <meta-data> 엔트리로써 관련 데이터를 제공하지 않는 것을 적극 권장한다. 대신에, 만약 여러분이 컴포넌트와 관련된 복잡한 데이터를 가지고 있다면, 리소스로 그것을 저장하고 그 리소스 ID의 컴포넌트를 알려주기 위해 resource 애트리뷰트를 사용하라.

attributes:
android:name
A unique name for the item. To ensure that the name is unique, use a Java-style naming convention for example, "com.example.project.activity.fred".
아이템에 대한 고유한 이름. 이름을 유일하게 하기 위해, 예를 들어 “com.example.project.activity.fred” Java 스타일 네이밍naming 규약을 사용하라.
android:resource
A reference to a resource. The ID of the resource is the value assigned to the item. The ID can be retrieved from the meta-data Bundle by the Bundle.getInt() method.
리소스에 대한 레퍼런스. 리소스의 ID는 아이템에 할당된 값이다. ID는 Bundle.getInt() 메쏘드에 의해 meta-data Bundle로부터 얻어질 수 있다.
android:value
The value assigned to the item. The data types that can be assigned as values and the Bundle methods that components use to retrieve those values are listed in the following table:
Type Bundle method
String value, using double backslashes (\\) to escape characters such as "\\n" and "\\uxxxxx" for a Unicode character. getString()
Integer value, such as "100" getInt()
Boolean value, either "true" or "false" getBoolean()
Color value, in the form "#rgb", "#argb", "#rrggbb", or "#aarrggbb" getString()
Float value, such as "1.23" getFloat()
아이템에 할당된 값. 값으로 할당될 수 있는 데이터 타입과 그것들의 값을 얻기 위해 사용하는 컴포넌트의 번들Bundle 메쏘드들이 아래의 테이블에 나열되어 있다.
타입 Bundle 메쏘드
유니코드 문자를 위한 “\\n” 와 “\\uxxxxx” 같은 이스케이프(escape) 캐릭터에 더블 백슬래시(\\)를 사용하는 문자열 값. getString()
“100”같은 정수(integer) 값. getInt()
“참(true)” 또는 “거짓(false)” 중 하나인 불리언 값. getBoolean()
“#rgb”,“#argb”,“#rrggbb” 또는 “#aarrggbb”형식의 컬러 값. getString()
“1.23” 같은 부동소수점 값, getFloat()
introduced in:
API Level 1
↑ Go to top