Reputation: 539
I was trying to convert an parcelable object into byte array, and in my class I have a byte type value. But when I marshal it using parcelable single byte is allocated 4 bytes in byte array. And in code I found parcel.writeByte internally call writeInt. Is there any way I can write a single byte into parcelable ?
Any help appreciated.
Upvotes: 1
Views: 197
Reputation: 4222
AFAIK, writing less than 4 bytes to Parcel is not possible with any currently available public API.
If you have up to 4 bytes, you can use ByteBuffer/bit shift to store them in the single integer value. You can also store arbitrary number of bytes (including a single byte) in a byte array. Doing so allows you to achieve any desirable memory layout, but incurs overhead of extra 4 bytes to store the array length.
Upvotes: 1