Android four component value Service (3) binding services

Source: Internet
Author: User

 bound service is the service that is allowed to be bound by the application component, and the binding can be done by calling Bindservice () 
Used to create a long-standing connection (and generally no longer allows the component to start the service by calling StartService (). When an activity or other component in the application needs to interact with the , or the application's to other applications,
you should create a bound service and complete it through interprocess communication (IPC). To create a bound service, you must implement the Onbind () callback method and return a IBinder object that defines the interface that communicates with the service. Other application components can then call Bindservice () to get the interface
and invoke the methods in the service. The service survives only when it is working for the bound application component, so as long as no component is bound to the service, the
system automatically destroys the service (you do not need to terminate a bound service by Onstartcommand () as in the started service). To create a bound service, you must first define the interface , which indicates How the client communicates with the service .
The The interface must be an implementation of an IBinder object , and your service must return this object in the Onbind ()
callback method. Once the client receives the IBinder, it can interact with the service through this interface. The same service can be bound by more than one client. When the client finishes the interaction, Unbindservice () is called to unbind.
Once the client and service bindings are not present, the service is destroyed. There are many ways to implement bound services, and the process of implementing them is more complex than started types of services,
so bound services will be discussed in a separate bound service document.

Android four component value Service (3) binding services

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.