0

I'm writing an Android Service which is intended to be bound by other Applications. It uses a Messenger as IBinder.

Now I've stumpled upon a Problem: If I want to send a Message with only a what and a String I originally planned to use Message.obj for it. This doesn't work as the documentation states:

When using Messenger to send the message across processes this can only be non-null if it contains a Parcelable of a framework class (not one implemented by the application). For other data transfer use setData(Bundle).

This raises two (related) questions:

  1. Why is a String not Parcelable in Android?
  2. Is there a more "elegant" solution than to create a Bundle for it and set my String there?
Rafael T
  • 15,401
  • 15
  • 83
  • 144

1 Answers1

1

1)Because its compatible with Java's String class, which isn't Parcelable (because that doesn't exist in the java standard library 2)Because it generally doesn't need to be- string can be sent over the wire natively without being a parcelable in most situations. You just found a weird corner case.

Gotta say, using a Message over a Binder is kind of odd. Generally you just send the data as individual parameters to a call.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I think `String` would still be compatible if it would be extended to Parcelable in Android. About the oddness for the Messenger as `IBinder`: I cannot use "individual parameters" If the Service is running in its own Process. I just followed the Instructions for Bound Services: https://developer.android.com/guide/components/bound-services#Messenger – Rafael T Apr 03 '19 at 16:41
  • If they changed the signature for string it would break every non android java library. They're not going to do that. And I've written plenty of binders and full out aidl. Never used a message – Gabe Sechan Apr 03 '19 at 16:42
  • Maybe I should look also into custom AIDL. One follow up question: Does custom aidl still enforce a max transfer limit of 1MB before throwing `TransactionTooLargeException` ? – Rafael T Apr 04 '19 at 13:06
  • Under the hour it all uses bundles. So yes, the seize limitations still exist. A way around them is to have an app give you a url for a file which you then read bugs a content provider – Gabe Sechan Apr 04 '19 at 13:19