Android Remote Services (AIDL) Implementation steps

Source: Internet
Author: User

AIDL is an abbreviation for the Android Interface definition language

Since the author is using Android studio, the location of the Aidl file should also be noted, in the Appname->main->aidl->packagename directory, the interface class file cannot be generated automatically

First, write our Aidl file, define the interface method, syntax is slightly different from Java

Secondly, we want to build the service class to implement the Aidl file name. The subclass of the stub class that implements the inherited method.

Returns an instance of this subclass in the Onbind method

Register the service and give it an action, which is the ID of the service to be accessed later

In activity, by intent set up action and Bindservice method to start the service, it is important to note that Android5.0 service in the intent must be explicit declaration, so we have to give intent set up our present package name, use the context of the getpackagename, and establish a serviceconnection instance, the method of implementing the instance, in Onservi The Ceconnected method can be used to obtain a subclass instance of the service pass through its parameter service.

With this example, we can invoke the method that serves the instance of the child class.

The above is a simple tutorial on the establishment and use of AIDL services.

Android Remote Services (AIDL) Implementation steps

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.