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)