1

I have an AIDL file where I want to return a list of integers. Simply like:

interface blah {
    List<Integer> getSubscriptionsForUser(int user);
}

But I can't do this because AIDL doesn't support java.lang.Integer it only supports primitives. But I can't do a list of primitives because java doesn't support primitve types.

Do I really need to make a custom parcelable class to make a list of integers that I can pass over binder? Or is there something obvious I'm just missing.

Andrew T.
  • 4,242
  • 3
  • 31
  • 50

1 Answers1

3

You can use int[] with AIDL interfaces

http://developer.android.com/guide/components/aidl.html#Create


To create your array you can use:

https://stackoverflow.com/a/9572820/413127

List<Integer> list = ...;
int[] array = new int[list.size()];
for(int i = 0; i < list.size(); i++) { array[i] = list.get(i) };

To create your list back on the other side you can use this method:

https://stackoverflow.com/a/2607335/413127

Integer[] array = new Integer[]{1, 2, 3};
List<Integer> list = Arrays.asList(array);
Community
  • 1
  • 1
Blundell
  • 69,653
  • 29
  • 191
  • 215