How to pass IBinder object between proccess?

Viewed 11

With intent, I share data between two processes (primitives only atm). Additionally, I want to pass IBinder object between them.

Since I know that Intent can contain Parcelable objects, and can therefore be shared between processes, I made a wrapper class that implements Parcelable to hold the IBinder, but it fails to share the intent with a marshalling error of the wrapper class (it cannot find the class).

Code example for the wrapper class -

public class IBinderParcel implements Parcelable {

  private IBinder binder;

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeStrongBinder(binder);
  }

  public static final Parcelable.Creator<IBinderParcel> CREATOR =
      new Parcelable.Creator<IBinderParcel>() {

        @Override
        public IBinderParcel createFromParcel(Parcel in) {
          return new IBinderParcel(in);
        }

        @Override
        public IBinderParcel[] newArray(int size) {
          return new IBinderParcel[size];
        }
      };

  public IBinderParcel(IBinder binder) {
    this.binder = binder;
  }

  private IBinderParcel(Parcel in) {
    readFromParcel(in);
  }

  private void readFromParcel(Parcel in) {
    this.binder = in.readStrongBinder();
  }

}

Do I have an issue with my wrapper class? Is there other way around?

Thanks.

0 Answers
Related