tags:

views:

157

answers:

3

I have a service that regularly queries a web server for new messages. The service stores the new messages in an arrayList. These messages are implemented using a custom class, storing all kinds of metadata (strings and longs).

An activity then connects to this service to retrieve those messages and display them to the user.

I have an .aidl file that describes the interface that the service exposes.

package com.example.package;

interface MyInterface {

    List<Message> getMessages();
}

The Message class extends the Parcelable class which should allow for the IPC transfer.

The problem is this: Eclipse gives me an error saying that the type of List<Message> is unknown. Any imports are marked as invalid.

Ideas? Thanks

A: 

I think Message is your class and not android.os.Message. If it is a custom class, then maybe it's the problem that the activity which wants to retrieve this class doesn't now the class Message. Make sure that this activity has this class in the classpath.

Roflcoptr
The activity and the Message classes are in the same package, so they should know about each other. It's the .aidl interface file that doesn't seem to know about the Message class. Thanks
Honza Pokorny
and where is this file? did you import the correct message and not android.os.message by accident
Roflcoptr
It's not really called Message in the real project. Where should this Message be imported? In the activity? Yep. In the Service? Yep. In the .aild? Nope, it won't let me. It says it's incorrect.
Honza Pokorny
The documentation (http://developer.android.com/guide/developing/tools/aidl.html) states that "Custom classes that implement the Parcelable protocol and are passed by value. An import statement is always needed for these." So I think the problem is that you cant import the Messsage class in your AIDL file. But why you can?T
Roflcoptr
I've read that bit like a thousand times :) Whenever I put a fully qualified import in just like it is shown in the example, it says it can't find the import class. I tried rebuilding the project to no avail.
Honza Pokorny
hmm ok then I would wait for CommonsWare ;)
Roflcoptr
+1  A: 

I have an .aidl file that describes the interface that the service exposes.

Why? You only need that for a remote service, and you only need a remote service if you are exposing an API to third-party applications.

If your service is a local service, get rid of the AIDL and use the local binding pattern instead.

If you truly do need AIDL, then you should be able to explicitly import your Parcelable class in your AIDL file, so it can be referenced. Your AIDL interface shown above does not have this import statement -- while it might not be needed for ordinary Java, it is needed for AIDL, since AIDL does not auto-import classes.

CommonsWare
How simple. Thank you very much. You rock!
Honza Pokorny
A: 

You need to create a aidl file for your Message class in the same package, like this:

package mypackage;

parcelable MyClass;

Then you will can use the import in the service aidl.

andrem