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