我需要知道如何使一个内部类Parcelable,以便可以通过AIDL将其类型的对象传递到远程服务。我找不到任何相关信息。
这是我尝试实现的示例代码,但它无法编译,因为Bar类中的CREATOR不能是静态的(即因为它在内部类中)。我不能将Bar设置为静态内部类,也不能将其移出Foo类(系统中有其他依赖项)。我还需要知道如何从AIDL文件中引用Bar类。非常感谢任何帮助。
public class Foo implements Parcelable
{
private int a;
public Foo()
{
}
public Foo(Parcel source)
{
this.a = source.readInt();
}
public int describeContents()
{
return 0;
}
public void writeToParcel(Parcel dest, int flags)
{
dest.writeInt(this.a);
}
public static final Parcelable.Creator<Foo> CREATOR
= new Parcelable.Creator<Foo>()
{
...
}
public class Bar implements Parcelable
{
private int b;
public Bar()
{
}
public Bar(Parcel source)
{
this.b = source.readInt();
}
public int describeContents()
{
return 0;
}
public void writeToParcel(Parcel dest, int flags)
{
dest.writeInt(this.b);
}
public static final Parcelable.Creator<Bar> CREATOR
= new Parcelable.Creator<Bar>()
{
...
}
}
}