parcelable ArrayList passed partially with null elements

北慕城南 提交于 2019-12-11 21:14:55

问题


when i pass an array between intents as a result to startActivityForResult I get a partial array back

ArrayList<User> currentUsers = ...

Intent resultIntent = new Intent();
resultIntent.putParcelableArrayListExtra(USER_ARR, currentUsers);
setResult(Activity.RESULT_OK, resultIntent);

ArrayList<User> users = data.getParcelableArrayListExtra(USER_ARR);

User implements Parcelable, and it is built correct for sure,

I changed something in the passing of the array and now when it sends the array

it is received on other side with many users being null, or all but one user being null

I also tried sending just a Parcelable[], and that did the same thing

please help


回答1:


found the answer :) I have no idea how it worked before fixing this

I was reading a byte array inside my parcelable only if the size of the byte array was bigger than zero, but not reading it did not advance the dataPosition()

thanks to this question Make custom Parcelable containing byte array I found the answer

have a great day everybody



来源:https://stackoverflow.com/questions/18469267/parcelable-arraylist-passed-partially-with-null-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!