Android Service Details (i)

Source: Internet
Author: User

Service is one of four components provided by the Android system its status and activity are tied only to the high frequency with which the activity is not used. Services are a service program that runs in the background and typically rarely interacts with the user, so there is no visual interface.


Defining a service class is simple, as long as the service class inherits the methods in its life cycle. A defined service must be declared in the Androidmanifest.xml configuration file through the <smice> element declaration in order to be used.


The service has its own life cycle, and we can call StartService () to start a service or use the Bindservice () method to bind an existing service. Also available via RPC (remote process Call) Mechanism to implement calls between different inter-process service.


Creating a service class is simple, as long as you define a class to inherit the service. Overwrite the corresponding method in the class. The service defines a series of methods related to its own declaration cycle, which are:

1, Onbind (Intent Intent): is a method that must be implemented to return a bound interface to the service.

2, OnCreate (): Called by the system when the service is first created.

3, OnStart (Intent intent,int startld): The method is called when the service is started through the StartService () method.

4, OnDestroy (): The system calls the method when the service is no longer in use.


The service uses the StartService (Intent Intent) method, which is very similar to initiating the activity and also passes a Intent. When the StartService () method is called, the called Service invokes its onCreate () method (if the service has not yet been created), and then calls the OnStart () method. Once the service is started, it will run until stopself () or StopService ()is called.


This article is from the "Useless Uncle" blog, please be sure to keep this source http://aslonely.blog.51cto.com/6552465/1615035

Android Service Details (i)

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.