Aidl and Binder Application

aidl--android interface define language.

First use aidl define a file named .aidl in the class folder. In the aidl file, you should define your interface class which includes abstract methods. Then in your gen folder, there will automatically generate a .java file which has the same name with .aidl file.

Second, you should create the service/client. In the service point, you should define one class which extends Service and define one object which implements the interface you defined in the .aidl. In the service, you should return the object (IBinder) in the function onBind().

client point, you should connect with the service, use startservice. And you will get the IBinder, then you can enter the servcie space.

Code:

原文地址:https://www.cnblogs.com/alexjie/p/2974039.html