如何打包一个 short[] 数组?
How to parcel a short[] array?
如何包裹以下参数?
short[] types;
从现在开始我试过这个:
// Write to parcel
dest.writeValue(types);
// Read from parcel
???
我怎样才能做到这一点?
简而言之,数组不能直接从包裹中写入和读取。
http://developer.android.com/reference/android/os/Parcel.html
你可以这样试试
// write
dest.writeInt(types.length);
for (int i = 0; i < types.length; i++) {
dest.writeInt((int) types[i]);
}
// read
len = parcel.readInt();
short[] types = new short[len];
for (int i = 0; i < len; i++) {
types[i] = (short) parcel.readInt();
}
如何包裹以下参数?
short[] types;
从现在开始我试过这个:
// Write to parcel
dest.writeValue(types);
// Read from parcel
???
我怎样才能做到这一点?
简而言之,数组不能直接从包裹中写入和读取。 http://developer.android.com/reference/android/os/Parcel.html
你可以这样试试
// write
dest.writeInt(types.length);
for (int i = 0; i < types.length; i++) {
dest.writeInt((int) types[i]);
}
// read
len = parcel.readInt();
short[] types = new short[len];
for (int i = 0; i < len; i++) {
types[i] = (short) parcel.readInt();
}