Creation of service
Service only needs to create a class and then inherit from service, life cycle only oncreat () and OnStop method ()
Binding
You can start the service with intent, or bind it by using the Bind method, Activicy inherits from Serviceconnection,bindservice (own intent,this,context.bind_auto_ CREATE), overriding the interface's two methods, Onserviceconnection and Onservicedisconnection. The service class overrides the Onbind method and lets it return the value of the binder type. You can create an inner class that inherits from Binder, and then instantiate an object that lets the IBinder method return this class.
Service runs in the background
If the service is started with intent, if not manually destroyed, the service will not stop even if the program stops running. If a service is bound, it should be untied before stop can turn off the service
If the service is run in a binding manner, the Activity destruction service ends
After binding, you can communicate with the activity
Gets the value in the service
The parameter of onserviceconnection in activity is the value returned in the service, that is, the class we created ourselves, in this class, create a method ret () to return to himself, Then define the Get method in the service class, in Activity Onserviceconnection, Ibinder.ret () assigns to a parameter of our own service type, then obtains the data through this parameter's Get method.
"Android" service