Home | History | Annotate | Download | only in manifest
      1 page.title=<service>
      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;service android:<a href="#enabled">enabled</a>=["true" | "false"]
      9          android:<a href="#exported">exported</a>=["true" | "false"]
     10          android:<a href="#icon">icon</a>="<i>drawable resource</i>"
     11          android:<a href="#label">label</a>="<i>string resource</i>"
     12          android:<a href="#nm">name</a>="<i>string</i>"
     13          android:<a href="#prmsn">permission</a>="<i>string</i>"
     14          android:<a href="#proc">process</a>="<i>string</i>" &gt;
     15     . . .
     16 &lt;/service&gt;</pre></dd>
     17 
     18 <dt>contained in:</dt>
     19 <dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code></dd>
     20 
     21 <dt>can contain:</dt>
     22 <dd><code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code>
     23 <br/><code><a href="{@docRoot}guide/topics/manifest/meta-data-element.html">&lt;meta-data&gt;</a></code></dd>
     24 
     25 <dt>description:</dt>
     26 <dd>Declares a service (a {@link android.app.Service} subclass) as one 
     27 of the application's components.  Unlike activities, services lack a 
     28 visual user interface.  They're used to implement long-running background 
     29 operations or a rich communications API that can be called by other 
     30 applications.
     31 
     32 <p>
     33 All services must be represented by {@code &lt;service&gt;} elements in 
     34 the manifest file.  Any that are not declared there will not be seen 
     35 by the system and will never be run.
     36 </p></dd>
     37 
     38 <dt>attributes:</dt>
     39 <dd><dl class="attr">
     40 <dt><a name="enabled"></a>{@code android:enabled}</dt>
     41 <dd>Whether or not the service can be instantiated by the system &mdash; 
     42 "{@code true}" if it can be, and "{@code false}" if not.  The default value 
     43 is "{@code true}".
     44 
     45 <p>
     46 The <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element has its own 
     47 <code><a href="{@docRoot}guide/topics/manifest/application-element.html#enabled">enabled</a></code> attribute that applies to all 
     48 application components, including services.  The 
     49 <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> and {@code &lt;service&gt;} 
     50 attributes must both be "{@code true}" (as they both
     51 are by default) for the service to be enabled.  If either is 
     52 "{@code false}", the service is disabled; it cannot be instantiated.
     53 </p></dd>
     54 
     55 <dt><a name="exported"></a>{@code android:exported}</dt>
     56 <dd>Whether or not components of other applications can invoke 
     57 the service or interact with it &mdash; "{@code true}" if they can, and 
     58 "{@code false}" if not.  When the value is "{@code false}", only 
     59 components of the same application or applications 
     60 with the same user ID can start the service or bind to it.
     61 
     62 <p>
     63 The default value depends on whether the service contains intent filters.  The 
     64 absence of any filters means that it can be invoked only by specifying 
     65 its exact class name.  This implies that the service is intended only for 
     66 application-internal use (since others would not know the class name).  So in 
     67 this case, the default value is "{@code false}".
     68 On the other hand, the presence of at least one filter implies that the service 
     69 is intended for external use, so the default value is "{@code true}".
     70 </p>
     71 
     72 <p>
     73 This attribute is not the only way to limit the exposure of a service to other
     74 applications.  You can also use a permission to limit the external entities that 
     75 can interact with the service (see the <code><a href="{@docRoot}guide/topics/manifest/service-element.html#prmsn">permission</a></code> 
     76 attribute).
     77 </p></dd>
     78 
     79 <dt><a name="icon"></a>{@code android:icon}</dt>
     80 <dd>An icon representing the service.  This attribute must be set as a 
     81 reference to a drawable resource containing the image definition.  
     82 If it is not set, the icon specified for the application 
     83 as a whole is used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> 
     84 element's <code><a href="{@docRoot}guide/topics/manifest/application-element.html#icon">icon</a></code> attribute).
     85 </p>
     86 
     87 <p>
     88 The service's icon &mdash; whether set here or by the 
     89 <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the 
     90 default icon for all the service's intent filters (see the 
     91 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's 
     92 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#icon">icon</a></code> attribute).
     93 </p></dd> 
     94 
     95 <dt><a name="label"></a>{@code android:label}</dt>
     96 <dd>A name for the service that can be displayed to users.  
     97 If this attribute is not set, the label set for the application as a whole is 
     98 used instead (see the <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's 
     99 <code><a href="{@docRoot}guide/topics/manifest/application-element.html#label">label</a></code> attribute).
    100 
    101 <p>
    102 The service's label &mdash; whether set here or by the 
    103 <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element &mdash; is also the 
    104 default label for all the service's intent filters (see the 
    105 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></code> element's 
    106 <code><a href="{@docRoot}guide/topics/manifest/intent-filter-element.html#label">label</a></code> attribute). 
    107 </p>
    108 
    109 <p>
    110 The label should be set as a reference to a string resource, so that
    111 it can be localized like other strings in the user interface.  
    112 However, as a convenience while you're developing the application, 
    113 it can also be set as a raw string.
    114 </p></dd>
    115 
    116 <dt><a name="nm"></a>{@code android:name}</dt>
    117 <dd>The name of the {@link android.app.Service} subclass that implements 
    118 the service.  This should be a fully qualified class name (such as, 
    119 "{@code com.example.project.RoomService}").  However, as a shorthand, if 
    120 the first character of the name is a period (for example, "{@code .RoomService}"),
    121 it is appended to the package name specified in the 
    122 <code><a href="{@docRoot}guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></code> element.  
    123 
    124 <p>Once you publish your application, you <a
    125 href="http://android-developers.blogspot.com/2011/06/things-that-cannot-change.html">should not
    126 change this name</a> (unless you've set <code><a
    127 href="#exported">android:exported</a>="false"</code>).</p>
    128 
    129 <p>
    130 There is no default.  The name must be specified.
    131 </p></dd>
    132 
    133 <dt><a name="prmsn"></a>{@code android:permission}</dt>
    134 <dd>The name of a permission that that an entity must have in order to 
    135 launch the service or bind to it.  If a caller of 
    136 <code>{@link android.content.Context#startService startService()}</code>,
    137 <code>{@link android.content.Context#bindService bindService()}</code>, or
    138 <code>{@link android.content.Context#stopService stopService()}</code>,
    139 has not been granted this permission, the method will not work and the
    140 Intent object will not be delivered to the service.
    141 
    142 <p>
    143 If this attribute is not set, the permission set by the 
    144 <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's
    145 <code><a href="{@docRoot}guide/topics/manifest/application-element.html#prmsn">permission</a></code> 
    146 attribute applies to the service.  If neither attribute is set, the service is
    147 not protected by a permission.
    148 </p>
    149 
    150 <p>
    151 For more information on permissions, see the 
    152 <a href="{@docRoot}guide/topics/manifest/manifest-intro.html#sectperm">Permissions</a> 
    153 section in the introduction and a separate document, 
    154 <a href="{@docRoot}guide/topics/security/security.html">Security and Permissions</a>.
    155 </p></dd>
    156 
    157 <dt><a name="proc"></a>{@code android:process}</dt>
    158 <dd>The name of the process where the service is to run.  Normally, 
    159 all components of an application run in the default process created for the 
    160 application.  It has the same name as the application package.  The 
    161 <code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code> element's 
    162 <code><a href="{@docRoot}guide/topics/manifest/application-element.html#proc">process</a></code> 
    163 attribute can set a different 
    164 default for all components.  But component can override the default
    165 with its own {@code process} attribute, allowing you to spread your 
    166 application across multiple processes.
    167 
    168 <p>
    169 If the name assigned to this attribute begins with a colon (':'), a new 
    170 process, private to the application, is created when it's needed and 
    171 the service runs in that process.
    172 If the process name begins with a lowercase character, the service will run 
    173 in a global process of that name, provided that it has permission to do so.
    174 This allows components in different applications to share a process, reducing 
    175 resource usage.
    176 </p></dd>
    177 </dl></dd>
    178 
    179 <dt>see also:</dt>
    180 <dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code>
    181 <br><code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code></dd>
    182 
    183 <!-- ##api level indication## -->
    184 <dt>introduced in:</dt>
    185 <dd>API Level 1</dd>
    186 
    187 </dl>
    188