3

for my application I need to pass data between my activity and the the service both of which are in different processes. I know that Google recommends to keep the data passed while sending intent to a minimum (not full size bitmaps). Does a similar policy apply when you are communicating with the service over AIDL and want to pass the data via remote method calls?

Onik
  • 15,592
  • 10
  • 57
  • 79
android_devrah
  • 250
  • 4
  • 11

2 Answers2

8

http://developer.android.com/reference/android/os/TransactionTooLargeException.html

" During a remote procedure call, the arguments and the return value of the call are transferred as Parcel objects stored in the Binder transaction buffer. If the arguments or the return value are too large to fit in the transaction buffer, then the call will fail and TransactionTooLargeException will be thrown.

The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. "

So it seems, you should never send any arguments which are more than 1MB in size. Of course you could fail with lesser sized arguments too as explained on android site above.

android_devrah
  • 250
  • 4
  • 11
1

I'm not sure about AIDL, but typically you DO want to keep Intent extras to a minimum. A better solution may be to implement your own ContentProvider and use that to provide data to your other process. This will allow for managed data transfer, and gives you all the extra protections that the ContentProvider API provides.

Codeman
  • 11,457
  • 8
  • 48
  • 89
  • I should have perhaps provided more details. My activity gets an array of bytes from the engine. It is possible, I might get a new array of bytes while the existing one has not been saved/is still being saved. I would like to keep these arrays in a RAM buffer before I can save them. That is what I was planning on doing in my service. – android_devrah Dec 08 '11 at 20:05
  • So create a static variable that stores these byte arrays? You need to be careful with how much data you are manipulating at once, though, since the Android VM limit is quite low, and I'm not sure what exactly you're doing. If it's anything with rendering, you may want to consider alternative solutions such as using a `Vertex Buffer Object` which manages buffering for you. – Codeman Dec 08 '11 at 20:12
  • A static variable will not be visible across 2 different processes. I need to pass the byte array from the activity process to the service process, so that service process can do the saving in the background, even if the activity itself exits. – android_devrah Dec 08 '11 at 20:26
  • 1
    Sorry, you did not mention it was an activity and a process. You should be using a `BroadcastReceiver` and a `ContentProvider` to manage this transaction, in my opinion. – Codeman Dec 08 '11 at 20:30
  • May be it was not very clear, but I mentioned it in my original question - "for my application I need to pass data between my activity and the the service both of which are in different processes." It is still not clear to me as to how you would pass data between processes? – android_devrah Dec 08 '11 at 20:33