Android service-declare a service in the list

Source: Internet
Author: User

Like Activity (and other components), all services must be declared in the application's configuration file.

To declare a service, you must add a <service> sub-element to the <Application> element. For example:

<Manifest...>
...
<Application...>
<Service android: Name = ". exampleservice"/>
...
</Application>
</Manifest>

The <service> element also contains some other attribute definitions, such as the license required to start the service and the process in which the service should run. The Android: Name attribute is a unique and mandatory attribute. It specifies the Class Name of the service. Once you publish an application, you should not change this name, because if you modify it, it will interrupt the functions that use intent to reference this service.

For more information about declaring a service in the configuration file, see <service> element description.

Like activity, a service can also define an intent filter, allowing other components to use an implicit intent to call this service. By declaring the intent filter, any application component installed on the user's device can start your service (If your service declares that one or more applications are passed to startservice () method intent match intent filter ).

If you plan to use your service only locally (other applications do not use it), you do not need to provide any intent filter (and should not provide it ). Without any intent filter, you must use an exact intent named service class to start this service. More information about starting a service will be discussed in the "Start a service" section.

In addition, if you include the Android: exported attribute in the <service> element and set the attribute value to "false", you can ensure that the service is a private service of your application. Even if the Service supports the intent filter, this is also valid.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.