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

后端 未结 12 1245
佛祖请我去吃肉
佛祖请我去吃肉 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:07

    You could also make use of the writeValue method. In my opinion that's the most straightforward solution.

    dst.writeValue( myBool );
    

    Afterwards you can easily retrieve it with a simple cast to Boolean:

    boolean myBool = (Boolean) source.readValue( null );
    

    Under the hood the Android Framework will handle it as an integer:

    writeInt( (Boolean) v ? 1 : 0 );
    

提交回复
热议问题