0

Here is the only thing I didn't get about AIDL and couldn't find anything on Google or Stackoverflow:

I have an activity and a service, each in different processes, and they tightly communicate via IPC using AIDL. One of the methods in AIDL communication interface needs to get list of my-custom-parcelable-class objects from service and return them to activity.

I'm confused with import statements in AIDL interface and on both ends in activity and service. In AIDL interface I import my .aidl parcelable declaration. Whereas if in activity and service I import my real (.java) parcelable class, and those declarations conflict, because AIDL interface implementation wants me to return .aidl parcelable but I return real parcelable.

I will try to make it more clear with code:

In my Service I'm sending list of MyParcelable:

import package-with-java-files.MyParcelable; // IMPORTING REAL MyParcelable
...
protected final InterprocessCommunicator.Stub binder = new InterprocessCommunicator.Stub() {
    @Override
    public List<MyParcelable> getMyParcelables() throws RemoteException { // CONFLICT
        return MyService.this.getMyParcelables();
    }
}

In my AIDL interface I declare method that returns the list:

package package-with-aidl-files;

import package-with-aidl-files.MyParcelable; // IMPORTING AIDL MyParcelable

interface InterprocessCommunicator {
    List<MyParcelable> getMyParcelables();
}

In my AIDL parcelable declaration (this is what I call AIDL MyParcelable):

package package-with-aidl-files;

parcelable MyParcelable;

In my java parcelable declaration (this is what I call real MyParcelable):

package package-with-java-files;

public class MyParcelable implements Parcelable {
    ...
}

Finally in my Activity I'm receiving list of MyParcelable:

import package-with-java-files.MyParcelable; // IMPORTING REAL MyParcelable
...
void someMethod() {
     List<MyParcelable> responses = interprocessCommunicator.getMyParcelables(); // CONFLICT
     ....
}

I hope now it's more clear where the conflicts are: in Service where I'm returning list of package-with-java-files.MyParcelable, but the AIDL interface expects package-with-aidl-files.MyParcelable and same thing in Activity

How to resolve those conflicts? I cannot import real MyParcelable in AIDL interface, nor I can import AIDL MyParcelable in Activity/Service...

AIDL experts, I need your help! Thanks in advance!

Please don't link me the official API guides, as there is nothing about it there http://developer.android.com/guide/components/aidl.html#PassingObjects

Makks129
  • 576
  • 5
  • 20

2 Answers2

1

AIDL is just a tool that helps you to generate the real implementation of proxies and stubs required for IPC. It takes an .aidl file and according to the rules generate from it .java files. These .java files are actual code that performs work. Thus, .aidl files can be imagined as nothing more then as an internal way helping to specify interface.

Therefore, in your case "package-with-aidl-files" will generate be also used to store generated .java files. Thus, "package-with-aidl-files" should correspond to "package-with-java-files". Hope, this explanation will help you!

Yury
  • 20,618
  • 7
  • 58
  • 86
1

You can't store the AIDL definition in a different package from the implementation. If you put your .java and .aidl files side-by-side it'll work.

j__m
  • 9,392
  • 1
  • 32
  • 56