我需要知道如何创建一个内部类Parcelable,以便它的类型的对象可以通过AIDL传递给远程服务。我找不到任何关于此的信息。如何创建一个内部类Parcelable
这是我正在尝试完成的示例代码,但它不能编译,因为Bar类中的CREATOR不能是静态的(即因为它在内部类中)。我不能让Bar成为静态内部类,并且我无法将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>()
{
...
}
}
}
你可以看看到http://stackoverflow.com/questions/35923039/android-implementing-parcelable-inner-class这将帮助你。 – chaitanya 2016-06-03 17:24:15
看看这个解决方案。这将帮助你http://stackoverflow.com/questions/35923039/android-implementing-parcelable-inner-class – chaitanya 2016-06-03 18:17:58