部分传递空元素的parcelable ArrayList [英] parcelable ArrayList passed partially with null elements

查看:25
本文介绍了部分传递空元素的parcelable ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在意图之间传递一个数组作为结果到 startActivityForResult我得到了一个部分数组

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);

用户实现了 Parcelable,它的构建肯定是正确的,

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

我也试过只发送一个 Parcelable[],结果是一样的

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

请帮忙

推荐答案

找到了答案 :)在解决这个问题之前我不知道它是如何工作的

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

我正在我的parcelable中读取一个字节数组仅当字节数组的大小大于零时,但不阅读它并没有推进 dataPosition()

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()

感谢这个问题 制作包含字节数组的自定义 Parcelable 我发现了回答

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

祝大家有个美好的一天

这篇关于部分传递空元素的parcelable ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆