1

The documentation states:

If you have a class that you would like to send from one process to another through an IPC interface, you can do that. However, you must ensure that the code for your class is available to the other side of the IPC channel and your class must support the Parcelable interface.

If I provide the .java file to the clients everything works. But I was wondering if there would be a way to pass the .class file instead or any other way to hide the source code.

cYrus
  • 2,976
  • 6
  • 29
  • 47

1 Answers1

1

But I was wondering if there would be a way to pass the .class file instead or any other way to hide the source code.

Shipping a JAR containing your Parcelable classes should work, though I haven't tried this.

Also, bear in mind that versioning becomes an issue -- what if you change these classes, and they do not update their JAR? This sort of complexity is why I do not recommend distributing Parcelable objects between applications this way.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Don't I have the same issue if they don't update the `.java` I provide? – cYrus May 07 '13 at 18:13
  • @cYrus: Yes. Which is why I do not recommend distributing `Parcelable` objects between applications this way. – CommonsWare May 07 '13 at 20:37
  • Are there any alternatives? I define an AIDL interface that uses a Parcelable object as a parameter. This interface is used by client applications, what do you suggest for deploying it? – cYrus May 08 '13 at 11:35
  • @cYrus: Don't define the AIDL interface using a custom `Parcelable`. Either pass simple values (ints, strings, etc.) or use platform-supplied `Parcelable` classes, like `Bundle`. Or, just never change the definition of your custom `Parcelable` classes. Or, abandon AIDL entirely and switch to the command pattern with services (`startService()` and `Intent` extras). – CommonsWare May 08 '13 at 11:38
  • I understand, but I cannot switch pattern. Besides that issue I was looking for a way to provide a single _package_ to the client. A ZIP containing `.aidl` and `.java` works fine but exposes the source code; a JAR cannot contain `.aidl` (at least, not in a way that allows me to automatically generate the `.java` from them, once I place it in `libs/`, right?). – cYrus May 08 '13 at 11:58
  • @cYrus: You are correct that a JAR cannot contain `.aidl` files that will be used by Android. Those you have to ship in source form. Again, you are welcome to use your own custom `Parcelable` classes -- it simply increases the "surface area" for possible versioning issues. This is not significantly different than dealing with different versions of a Web service API, except that you do not have as much flexibility in Android. – CommonsWare May 08 '13 at 12:03
  • 1
    One other comment - since you're defining the `Parcelable` you can, and probably should, add a version number within the parcel-ised representation. Then at least the recipient can detect errors instead of misinterpreting data and crashing (or worse, exposing security bugs). – Adrian Taylor May 30 '13 at 09:32