在意图之间传递ArrayList会丢失数据 [英] Passing ArrayList between intents loses data

查看:249
本文介绍了在意图之间传递ArrayList会丢失数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将ArrayList<Custom implements Parcelable> myList传递给Intent. 将ArrayList放入新的Intent中,以下两种方法似乎都可以正常工作.

I am passing ArrayList<Custom implements Parcelable> myList to an Intent. Both of the following ways seem to work fine with putting the ArrayList into the new Intent.

        results.putParcelableArrayListExtra("list", myList);
        results.putExtra("list", myList);

当我检查mIntent/mExtras/mMap/table时,那里的所有内容.但是在意图的onCreate方法中,某些数据似乎丢失了.我现在用myList = (ArrayList<Custom>) this.getIntent().getParcelableArrayListExtra("list");

When I check mIntent/mExtras/mMap/table it is everything there. But in the onCreate method of the intent some of that data seems to be lost. I am getting the ArrayList then with myList = (ArrayList<Custom>) this.getIntent().getParcelableArrayListExtra("list");

例如,列表包含五个项目[a],[b],[c],[d]和[e]:

For example the list contains five items[a], [b], [c], [d] and [e]:

put...   get...
[a]  ->  [a]
[b]  ->  null
[c]  ->  [b]
[d]  ->  null
[e]  ->  [c]

似乎新列表中的第二个项目都不是预期的,并且占据了最后缺少的一个位置. 你能告诉我我做错了什么吗?

It seems that every second item in the new list is not intended and takes up one place that is missing at the end. Can you tell me what I am doing wrong?

推荐答案

尝试这个为我的朋友:

intent.putParcelableArrayListExtra("tag",yourObjectImplementsParceable);

xxx = (ArrayList<yourClassImplementsParceable>) intent.getParcelableArrayListExtra("tag");

希望这会有所帮助

这篇关于在意图之间传递ArrayList会丢失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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