I am trying to use a shared object for several services in different packages. Each service must call the same object.
For example, service A (from APK A) creates an instance of a custom object, and I want services B and C (from APK B and C) to extract a reference to this object and call some method of it.
I found in the Android reference that this should be possible with Parcel :
Active objects
An unusual feature of Parcel is the ability to read and write objects. For these objects, the actual contents of the object is not written, but rather a special token that refers to the object. When you read an object back from the Parcel, you are not getting a new instance of the object, but rather a descriptor that works with the exact same object that was originally written. There are two forms of active objects available.
Binder objects are the primary means of the overall cross-process Android communication system. The IBinder interface describes an abstract protocol with a Binder object. Any such interface can be written to the Package, and after reading you will receive either the source object of the implementation of this interface or a special proxy implementation that provides feedback to the source object. Ways to use writeStrongBinder (IBinder), writeStrongInterface (IInterface), readStrongBinder (), writeBinderArray (IBinder []), readBinderArray (IBinder []), createBinderArray (), writeBinderList (List), readBinderList (List), createBinderArrayList ().
I tried to do this by passing my object (which extends the middleware) through AIDL, but nothing works, I always get a ClassCastException when I try to get a link from the createFromParcel (Parcel in) method.
An example of my code:
public class CustomObject extends Binder implements Parcelable { public CustomObject() { super(); } public static final Parcelable.Creator<CustomObject> CREATOR = new Parcelable.Creator<CustomObject>() { public CustomObject createFromParcel(Parcel in) { IBinder i = in.readStrongBinder();
Has anyone already done this?
Thanks in advance!