How to use Parcelable in AIDL

元气小坏坏 提交于 2021-02-07 10:27:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!