How to read/write a boolean when implementing the Parcelable interface?

后端 未结 12 1256
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 14:33

I\'m trying to make an ArrayList Parcelable in order to pass to an activity a list of custom object. I start writing a myObjectList cl

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 15:22

    Here's how I'd do it...

    writeToParcel:

    dest.writeByte((byte) (myBoolean ? 1 : 0));     //if myBoolean == true, byte == 1
    

    readFromParcel:

    myBoolean = in.readByte() != 0;     //myBoolean == true if byte != 0
    

提交回复
热议问题