Android -- android.os.Parcelable[] cannot be cast to ...
我本想直接把Bunde.getParcelableArray(...)得到的Parcelable[]强制转换为自定义类数组,但是失败了,网上找了两种解决办法:
Parcelable[] data =bundleGet.getParcelableArray(MessageApi.ARG_GET_DATA_RESULT);
CustomData[] customData = new CustomData[data.length];
// This approach is ok.
// customData = Arrays.copyOf(data, data.length, CustomData[].class);
// This approach is ok too.
for(int i = 0; i < data.length; i++){
customData[i] = (CustomData) data[i];
}
一种是通过Arrays.copeOf(...).
一种是通过for循环,一个一个的强制转换。