传递一个列表从一个活动到另一个 [英] Passing a List from one Activity to another

查看:99
本文介绍了传递一个列表从一个活动到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过集合像的ArrayList 等从一个活动到另一个我们用来传递字符串 INT 意图的putExtra方法的帮助?

How to pass Collections like ArrayList, etc from one Activity to another as we used to pass Strings, int with help of putExtra method of Intent?

任何人都可以请帮助我,我想通过一个名单,其中,字符串> 从一个活动到另一个?

Can anyone please help me as i want to pass a List<String> from one Activity to another?

推荐答案

您可以传递一个的ArrayList&LT; E&GT; 以同样的方式,如果 Ë的类型是序列化

You can pass an ArrayList<E> the same way, if the E type is Serializable.

您会调用 putExtra(字符串名称,序列化值)意图来存储,而 getSerializableExtra(字符串名称)检索。

You would call the putExtra (String name, Serializable value) of Intent to store, and getSerializableExtra (String name) for retrieval.

例如:

ArrayList<String> myList = new ArrayList<String>();
intent.putExtra("mylist", myList);

在其他活动:

ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("mylist");


请注意,序列化可能会导致性能问题。这需要时间和大量的对象将被分配(因此,必须收集的垃圾)

这篇关于传递一个列表从一个活动到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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