0

I am using Binder for communication between two processes. Suppose process A (server) creates a Binder and passes it to process B (client). Process B calls the relevant interfaces on the received IBinder.

I know that B can monitor if process A is killed by using linkToDeatch() on that IBinder. The question I would like to ask is.

  1. Is there any way for A to be notified that process B is killed (except for ping).
  2. How to release the resource related to the Binder? directly assign binder to null?
progquester
  • 1,228
  • 14
  • 23

1 Answers1

1

Process A can implement the onBinderDied() method of the DeathRecipient interface on the IBinder object that was passed to B. When B is killed, the binderDied() method will be called, and can be used by A to release resources and cleanup.

DeathRecipient deathRecipient = new DeathRecipient() {
    @Override
    public void binderDied() {
        Log.d(TAG, "binderDied");
        // process B has died, perform cleanup here
        mBinder.asBinder.unlinkToDeath(this, 0);
    }
};
mBinder.linkToDeath(deathRecipient, 0);
Allen Shaw
  • 1,164
  • 7
  • 23