Android: Making a class parcelable

后端 未结 5 896
无人及你
无人及你 2020-12-15 06:32

I want to pass on object between two activities in Android which has lead me to parcelable classes. I am not trying to convert my current class but don\'t understand the Par

5条回答
  •  天涯浪人
    2020-12-15 06:58

    public static final Parcelable.Creator CREATOR =
        new Parcelable.Creator() {
            public ObjectB createFromParcel(Parcel in) {
                return new ObjectB(in);
            }
    
            public ObjectB[] newArray(int size) {
                return new ObjectB[size];
            }
        };
    

    This field is needed for Android to be able to create new objects, individually or as arrays. This also means that you can use use the default constructor to create the object and use another method to hyrdate it as necessary.

    Look at this Android – Parcelable

    Online tool for creating Parcelable class

    and http://www.appance.com/tag/parcelable/

提交回复
热议问题