我有一个实现Parcelable
接口(interface)的类:
class A implements Parcelable {
}
我有另一个类 B
包含一个 A
对象作为实例变量。在类 B
内的 writeToPacel
中,我想将对象 B
写入 Parcel
:
class B implements Parcelable{
public void writeToParcel(Parcel dest, int flags) {
dest.write ???
}
}
如何写和读?
最佳答案
class B implements Parcelable{
//lets assume you have A as a data member
A obj;
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(obj , flags);
}
}
如果您想阅读它,请使用此
obj = in.readParcelable(A.class.getClassLoader());
关于android - 将 Parcelable 的一个子类写入另一个 Parcel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12239343/