A service is an application component that runs in the background and does not interact with the user. As with activity, each service must be declared in the manifest by <Service>. Can be started by StartService and Bindserverice.
Service, like other application components, runs in the main thread. This means that if the service requires a lot of time-consuming or blocking operations, it needs to be implemented in its child threads.
The two Modes of service (StartService ()/bindservice () are not completely detached):Local ServiceThe Local Service is used inside the application. Call Context.startservice () to start, call Context.stopservice () to end. It can call Service.stopself () or Service.stopselfresult () to stop itself. No matter how many times the StartService () method is called, you only need to call once StopService () to stop the service.Remote ServiceRemote Service is used between applications within the Android system. It can be manipulated by its own defined and exposed interfaces. The client establishes a connection to the service object and invokes the service through that connection. The connection is established to call the Context.bindservice () method to call Context.unbindservice () to close. Multiple clients can bind to the same service. If the service is not loaded at this time, bindservice () loads it first.
Life cycle
context.startservice () ->oncreate ()->onstart ()->service running--call Context.stopservice () OnDestroy ()
Context . Bindservice ()->oncreate ()->onbind ()->service running--call >onunbind (), OnDestroy ()
In addition, the acitity sends a message to the service available IBinder, which can be implemented with Broadcastreceiver if the service sends a message to the activity.
Resources:
Http://www.cnblogs.com/zhangdongzi/archive/2012/01/08/2316711.html
http://android.blog.51cto.com/268543/527314/
http://zhangyan1158.blog.51cto.com/2487362/491358
Service of Android four components