问题
I define a class which implements Parcelable
, like this:
public class Book implements Parcelable
And I know I can use this class in AIDL file like this:
import com.okay.demo.aidl.bean.Book;
interface IBookManager {
void addBook(in Book book);
}
But what I want to know is that can I just Parcelable
in AIDL file suppose I don't know the implementation class? Can I just use Parcelable
like this :
interface IBookManager {
void addData(in Parcelable data);
}
I had tried replace Book
with Parcelable
, but it didn't work.
Or can not it do this in AIDL ?
回答1:
Android documentation says you should create an AIDL file for your class Book
. Your Book.aidl
should look like:
import com.okay.demo.aidl.bean.Book;
// Declare Rect so AIDL can find it and knows that it implements
// the parcelable protocol.
parcelable Book;
With this new file, you can now use Book
in your AIDL file:
import com.okay.demo.aidl.bean.Book;
interface IBookManager {
void addData(in Book book);
}
来源:https://stackoverflow.com/questions/43962237/how-to-use-parcelable-in-aidl