Android implements multi process communication by inheriting binder class

The bottom layer of Aidl communicates through binder. By tracking the files automatically generated after compiling. Aidl, we know that the stub class in the file is used for the server and the proxy class is used for client calls. Can we directly realize multi process communication by inheriting binder class? Let's have a try.

design sketch:

Server code, binderservice.java:

First, inherit the binder class, implement ontransact() for the client to call, and return the binder instance through onbind():

Declare the following in androidmanifest.xml:

Client code: binderactivity.java:

First, write the serviceconnection class to obtain the binder instance to send and receive data:

Then the binding service:

The code is also very simple. The apple class used in it has implemented the serialization of the paceable interface. Data transmission between processes is a process of data serialization and deserialization~

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>