4

I have this method in my .aidl file:

void getObjects(out List<MyObject> objList);

But I get this error

src/com/mycompany/mypackage/ITestService.aidl:26 parameter objList (1) unknown type List objList

How to create a List of MyObject in .aidl?

Thank you.

n179911
  • 19,547
  • 46
  • 120
  • 162

2 Answers2

5

Steps:

  1. MyObject implements Parcable

  2. Create new MyObject.aidl file in src.com.mycompany.mypackage

      package src.com.mycompany.mypackage;
      parcelable MyObject;
    

    Reason :you’re passing class objects between processes, the client process must understand the definition of the object being passed.

    AIDL complier won’t be able to locate our self-defined MyObject even if it implements the Parcelable interface. To inform our implementation to the AIDL compiler, we need to define an aidl file which declares the class as Parcelable

  3. In ITestService.aidl add import statment,

    import src.com.mycompany.mypackage.MyObject
    

Error unknown type List will get removed.

R World
  • 766
  • 9
  • 26
0

You need to make MyObject Parcelable and then import MyObject in your AIDL file.

For more information and an example see the developers guide: https://developer.android.com/guide/developing/tools/aidl.html#PassingObjects