title: Pass active objects between services through AIDL
body: <p>I'm trying to have a common object shared for several services in different packages. Each service must call the same object.</p>
  
  <p>For example, Service A (from APK A) instantiates a custom object and I want that Service B and C (from APK B and C) retrieves the reference of this object and call some method of it.</p>
  
  <p>I found in the Android reference that it should be possible by using <a href="http://developer.android.com/reference/android/os/Parcel.html" rel="nofollow">Parcel</a> : </p>
  
  <blockquote>
    <p><strong>Active Objects</strong></p>
    
    <p>An unusual feature of Parcel is the ability to read and write active
    objects. For these objects the actual contents of the object is not
    written, rather a special token referencing the object is written.
    When reading the object back from the Parcel, you do not get a new
    instance of the object, but rather a handle that operates on the exact
    same object that was originally written. There are two forms of active
    objects available.</p>
    
    <p>Binder objects are a core facility of Android's general cross-process
    communication system. The IBinder interface describes an abstract
    protocol with a Binder object. Any such interface can be written in to
    a Parcel, and upon reading you will receive either the original object
    implementing that interface or a special proxy implementation that
    communicates calls back to the original object. The methods to use are
    writeStrongBinder(IBinder), writeStrongInterface(IInterface),
    readStrongBinder(), writeBinderArray(IBinder[]),
    readBinderArray(IBinder[]), createBinderArray(),
    writeBinderList(List), readBinderList(List), createBinderArrayList().</p>
  </blockquote>
  
  <p>I tried to do this by passing my object (who extends binder) through AIDL but nothing works, I always gets a ClassCastException when I'm trying to retrieve the reference from the method createFromParcel(Parcel in).</p>
  
  <p>An example of my code : </p>
  
  <pre><code>public class CustomObject extends Binder implements Parcelable {
  
    public CustomObject() {
      super();
    }
  
    public static final Parcelable.Creator&lt;CustomObject&gt; CREATOR = new Parcelable.Creator&lt;CustomObject&gt;() {
    public CustomObject createFromParcel(Parcel in) {
      IBinder i = in.readStrongBinder();
        // HOW TO RETRIEVE THE REFERENCE ??
        return null;
      }
  
      @Override
      public CustomObject[] newArray(int size) {
        return null;
      }
    };
  
    @Override
    public int describeContents() {
      return 0;
    }
  
    @Override
    public void writeToParcel(Parcel dest, int flags) {
      dest.writeStrongBinder(this);
    }
  }
  </code></pre>
  
  <p>Is anyone has already done that ? </p>
  
  <p>Thanks in advance ! </p>