How to create Aidl in Android Studio

Source: Internet
Author: User

Implement Client Add Book,service receive and print out book information first, create the books class

1. Create a folder (this article is named Aidl)

2. Create the book class and Inherit the Parcelable interface (reason: Aidl can only transfer classes that inherit parcelable interfaces)

See: Chapter II Use of--parcelable interfaces (cross-process, intent transmission)

Two. Create Aidl folder with Book.aidl

Use Aidl file to fill in the name of the time to fill in the first (because if the direct fill in the name of the book will be an error, only after the creation of the rename will not error)

Then becomes

Why should there be a book.aidl class, because Aidl can call the book class only when the class is declared in Aidl, and then how to declare

So for Aidl to be able to transfer custom classes requires ① to inherit parcelable interface ② Create the same name. aidl file Declare yourself.

Iii. Creating a Ibookmanager.aidl (role: Setting the interface that allows the client to invoke)

Iv. analysis of the operating principle of binder

Note: Stub objects can be understood as binder classes

1. The system will automatically generate Ibookmanger.java files

Analyze its properties and methods
Descriptor: Binder's Unique Table identifier, "generally denoted by class name"

asinterface (IBinder obj): Converts the Binder object on the service side to the desired Aidl object of the client.

①: If the client and the server are in the same process, the stub itself is returned to the service side.

②: The Stub.proxy object is returned if the client and server are in different processes.

Asbinder (): Returns the current binder object

ontransact (): This method is called when the client initiates a cross-process request and returns Stub.proxy

proxy#getbooklist (): The interface we just created.

Operating principle:

Well, the principle of operation and the way to create it is here.

How to create Aidl in Android Studio

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.