Write a sub class of Parcelable to another Parcel

前端 未结 3 2094
盖世英雄少女心
盖世英雄少女心 2020-12-23 09:15

I have a class that implements Parcelable interface:

class A implements Parcelable {

}

I have another class B th

3条回答
  •  青春惊慌失措
    2020-12-23 09:36

    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);
    
        }
    }
    

    if you want to read it use this

     obj = in.readParcelable(A.class.getClassLoader());
    

提交回复
热议问题