Here are two approaches.
Simple: use aidl for the object itself
- It seems you have an existing AIDL interface through which you pass this 'custom object' as a parcel. Don't do that. Instead:
- The object which you pass through should be itself described by AIDL. Say, for example, you call it
ICustomObject.aidl
. In this case you do not need to make the object Parcelable. You probably don't even need to write the above code; just use one AIDL-described type in another. For example add a line like this to the main AIDL for service A:
ICustomObject getCustomObject();
In service A, within the
Stub
class you've already got, you'll need to simply return something inheriting fromICustomObject
.- In services B and C, you can simply call that method to get hold of an
ICustomObject
. Simple! No parcels, noreadStrongBinder()
, nothing.
Harder
If you do the above, the Android toolchain generates Java code which marshalls and unmarshalls the object. You could instead write the code yourself.
ICustomObject myObjectWhichActuallyLivesInAnotherProcess = ICustomObject.Stub.asInterface(parcel.readStrongBinder())
or even
ICustomObject myObjectWhichActuallyLivesInAnotherProcess = (ICustomObject)parcel.readStrongBinder().queryLocalInterface("com.your.custom.object");
However I think your life will be more sane if you make everything aidl.
A note on class sharing
You'll probably want to create an Android "library project" which has ICustomObject.aidl
within it, such that you can share the resulting classes between the projects which build A, B and C.