可拆分ArrayList部分传递带有null元素 [英] parcelable ArrayList passed partially with null elements

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

问题描述

当我将两个意图之间的数组作为结果传递给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

我正在读取包裹中的字节数组 仅当字节数组的大小大于零时, 但不读取它并不会推动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 回答

祝大家有美好的一天

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

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