android IPC binder communication mechanism

  • 2020-05-07 20:23:21
  • OfStack

The Binder communication mechanism is simple to say, but I met some problems in the process of using, and finally solved them. In this summary, I will share with you:
1, to use Binder communication, first to define the interface, and then implement the server BnInterface*** and the client BpInterface***, after all, 1 is to unpack parameters, 1 is to package parameters.
2, the server side to be able to receive Binder call request, to have two conditions: 1 is to implement Bn interface, another is to call IPCProcess () - "self- > startThreadPool()
IPCThread()- > Self- > joinThreadPool();
These two sentences are very critical, because he started a thread in the background, responsible for reading the Binder interface call request, and then call the specific interface, if not this thread, your service will not receive the call request, the client will call failure (died).
Likewise on the client side, if callbacks are to be supported, the thread reading the Binder call must also be started; otherwise, the callback fails.

Related articles: