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