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