1

I'm using an Android IBinder interface to read data from a service. My specific case dictates that I don't know exactly what object I'll be receiving from that service (due to versioning and server side business logic).

From the samples and examples I've seen - when you know which class you'll receive - you can make it parcelable and read it directly from the parcel but for me - this is not relevant.

Is there a way to extract the information received in the parcel without knowing it's structure ? possibly using the parcel meta data or reflection?

I couldn't find any examples online. Any help would be greatly appreciated.

5
  • "I'm using an Android IBinder interface to read data from a service" -- unless that service is in some other process from your client, the simplest solution is to get rid of the IBinder and just work with ordinary objects, so you can avoid the Parcel. Commented Aug 29, 2022 at 12:29
  • Thanks @CommonsWare, but the service is in an external process. We have to use IBinder. Commented Aug 29, 2022 at 12:43
  • Then unless the first couple of items in the Parcel are standardized and let you know how to interpret the rest, I think you're in trouble. For example, if all of the Parcel objects start with some integer or string, and from there you know enough to be able to decide how to read in a bit more, you might be able to pull this off. Commented Aug 29, 2022 at 12:58
  • I think this would require a very generic approach to umarshalling if the contract, because of versioning, is very loose. If there is a version mismatch then reflection won't help if used with something like Class.forName("com.my.object").newInstance() as the Object might not match what is expected. Maybe you could think about simple key/value pairs, like a Map<String, Object>. Could you use AIDL instead, or even a ContentProvider which might provide a better contract? Commented Aug 29, 2022 at 13:35
  • Thanks @Mark , but my specific project is such that I don't have control over the server side which provides the parcel object. It's passed using an IBinder interface and that it. No option to use other ways ContentProvider or other methods. I'm trying to find a way to parse the Parceled object generically. Commented Aug 29, 2022 at 13:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.