• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=<meta-data>
2@jd:body
3
4<dl class="xml">
5<dt>syntax:</dt>
6<dd><pre class="stx">&lt;meta-data android:<a href="#nm">name</a>="<i>string</i>"
7           android:<a href="#rsrc">resource</a>="<i>resource specification</i>"
8           android:<a href="#val">value</a>="<i>string</i>" /&gt;</pre></dd>
9
10<dt>contained in:</dt>
11<dd><code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
12<br/><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html">&lt;activity-alias&gt;</a></code>
13<br/><code><a href="{@docRoot}guide/topics/manifest/service-element.html">&lt;service&gt;</a></code>
14<br/><code><a href="{@docRoot}guide/topics/manifest/receiver-element.html">&lt;receiver&gt;</a></code></dd>
15
16<dt>description:</dt>
17<dd>A name-value pair for an item of additional, arbitrary data that can
18be supplied to the parent component.  A component element can contain any
19number of {@code &lt;meta-data&gt;} subelements.  The values from all of
20them are collected in a single {@link android.os.Bundle} object and made
21available to the component as the
22{@link android.content.pm.PackageItemInfo#metaData
23PackageItemInfo.metaData} field.
24
25<p>
26Ordinary values are specified through the <code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html#value">value</a></code>
27attribute.  However, to assign a resource ID as the value, use the
28<code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html#resource">resource</a></code> attribute instead.  For example,
29the following code assigns whatever value is stored in the {@code @string/kangaroo}
30resource to the "{@code zoo}" name:
31</p>
32
33<pre>&lt;meta-data android:name="zoo" android:value="@string/kangaroo" /&gt;</pre>
34
35<p>
36On the other hand, using the {@code resource} attribute would assign "{@code zoo}"
37the numeric ID of the resource, not the value stored in the resource:
38</p>
39
40<pre>&lt;meta-data android:name="zoo" android:resource="@string/kangaroo" /&gt;</pre>
41
42<p>
43It is highly recommended that you avoid supplying related data as
44multiple separate {@code &lt;meta-data&gt;} entries. Instead, if you
45have complex data to associate with a component, store it as a resource and
46use the {@code resource} attribute to inform the component of its ID.
47</p></dd>
48
49<dt>attributes:</dt>
50<dd><dl class="attr">
51<dt><a name="nm"></a>{@code android:name}</dt>
52<dd>A unique name for the item.  To ensure that the name is unique, use a
53Java-style naming convention &mdash; for example,
54"{@code com.example.project.activity.fred}".</dd>
55
56<dt><a name="rsrc"></a>{@code android:resource}</dt>
57<dd>A reference to a resource.  The ID of the resource is the value assigned
58to the item.  The ID can be retrieved from the meta-data Bundle by the
59{@link android.os.Bundle#getInt Bundle.getInt()} method.</dd>
60
61<dt><a name="val"></a>{@code android:value}</dt>
62<dd>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:
63
64<table>
65<tr>
66  <th>Type</th>
67  <th>Bundle method</th>
68</tr><tr>
69  <td>String value, using double backslashes ({@code \\}) to escape characters
70      &mdash; such as "{@code \\n}" and "{@code \\uxxxxx}" for a Unicode character.</td>
71  <td>{@link android.os.Bundle#getString(String) getString()}</td>
72</tr><tr>
73  <td>Integer value, such as "{@code 100}"</td>
74  <td>{@link android.os.Bundle#getInt(String) getInt()}</td>
75</tr><tr>
76  <td>Boolean value, either "{@code true}" or "{@code false}"</td>
77  <td>{@link android.os.Bundle#getBoolean(String) getBoolean()}</td>
78</tr><tr>
79  <td>Color value, in the form "{@code #rgb}", "{@code #argb}",
80      "{@code #rrggbb}", or "{@code #aarrggbb}"</td>
81  <td>{@link android.os.Bundle#getString(String) getString()}</td>
82</tr><tr>
83  <td>Float value, such as "{@code 1.23}"</td>
84  <td>{@link android.os.Bundle#getFloat(String) getFloat()}</td>
85</tr>
86</table>
87</dd>
88</dl></dd>
89
90<!-- ##api level indication## -->
91<dt>introduced in:</dt>
92<dd>API Level 1</dd>
93
94</dl>
95