在意图之间传递 ArrayList 会丢失数据 [英] Passing ArrayList between intents loses data
问题描述
我正在传递 ArrayList
到一个意图.将 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
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屋!