如何使用 Parcel.readBooleanArray()?
我正在尝试使用 android.os.Parcel 中的 readBooleanArray,但 readBooleanArray 返回 void,因此我不清楚如何使用此方法。
我正在使用以下方法向 Parcel 写入一些内容:
public void writeToParcel(Parcel out, int flags) {
out.writeBooleanArray(new boolean[] {value});
}
如何在 Parcelable 构造函数中获取此值?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您需要传递一个 boolean[],Parcel 中的值将被复制到其中,然后您从该数组中读取。
示例代码:
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:
如果您有一个真正的布尔数组,而不仅仅是一个值,并且您不知道数组的长度,那么您可以使用
createBooleanArray()
而不是readBooleanArray(boolean[])
。它将返回一个新数组,该数组与您使用 writeBooleanArray(boolean[]) 放入包中的数组相同。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 ofreadBooleanArray(boolean[])
. It will return a new array which is the same you put into the parcel withwriteBooleanArray(boolean[])
.