Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Parcel.readBooleanArray()?

I'm trying to use the readBooleanArray from android.os.Parcel, but readBooleanArray returns void and therefor it's unclear to me how to use this method.

I'm using the following method to write something to the Parcel:

public void writeToParcel(Parcel out, int flags) {
    out.writeBooleanArray(new boolean[] {value});
}

How should this value be obtained in the Parcelable constructor?

like image 776
Joost Avatar asked Aug 29 '11 13:08

Joost


2 Answers

I believe you need to pass a boolean[], the values in the Parcel will be copied to that, then you read from that array.

Sample code:

boolean[] myBooleanArr = new boolean[1];
parcel.readBooleanArray(myBooleanArr);
boolean value = myBooleanArr[0];
like image 134
C0deAttack Avatar answered Oct 03 '22 23:10

C0deAttack


If you have a real boolean array, not only one value, and you don't know the length of the array, then you can use createBooleanArray() instead of readBooleanArray(boolean[]). It will return a new array which is the same you put into the parcel with writeBooleanArray(boolean[]).

like image 24
hunyadym Avatar answered Oct 04 '22 00:10

hunyadym