Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Let's say there are two processes. I am interested in making an AIDL call (e.g. byte[] getBytes() ) from an Activity (Process A) to a Service (Process B) which returns a byte[] of data.

However when this byte[] of data exceeds 1MB, it triggers the following expected exception. This also happens if the byte[] is wrapped inside of a custom Parcelable class.

W Error = android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
W   at android.os.BinderProxy.transactNative(Native Method)
W   at android.os.BinderProxy.transact(BinderProxy.java:571)

This appears to be caused by the data limits documented here: https://developer.android.com/guide/components/activities/parcelables-and-bundles

However, if the AIDL API returns a Bitmap (e.g. Bitmap getBitmap() ) containing data for an image that exceeds 1MB, this exception does not get triggered. Why does it work? In general, if I'd like to send data over 1MB, what would be the preferred method? In this test case, it's using an image file for the Bitmap but what if it is an audio file, video file or something else?

It depends. An implementation of Bitmap may not contain all of the image data in an array- it may contain information needed to get that data. For example, it may contain the filename of an image, and accessing the data would try to reopen the file. (whether that would work would depend on access rights of both apps). Or provide the URI of a content provider it can query for the data. Could that technique work with other data? Yes, if there's a reasonable way to do that. But there needs to be a way for the receiving app to reacquire the full data set.

However the 1MB limit to the size of a Bundle (the underlying class used to send data via AIDL) is hardcoded at the OS level. You can't get around it and put more in the bundle. You can only do a misdirection like this.

Thank you! This was helpful. Is this because the Bitmap uses shared memory under the hood: developer.android.com/reference/android/graphics/Bitmap ? In general, what would be the guidance for sending over data for a file (e.g. image, audio, video) across AIDL? Would a ParcelFileDescriptor be an option in case the app does not use MediaStore APIs? Or would URI of a content provider be the recommended way? How about SharedMemory : developer.android.com/reference/android/os/SharedMemory ? – code Feb 1 at 6:35

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.