1

我正在尝试ArrayList<HashMap<String, String>>在活动之间传递。我将如何使用 Intents 做到这一点?

4

2 回答 2

2

ArrayList 是可序列化的(以及 HashMap 和字符串),所以试试putExtra(String, Serializable).

ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
Intent intent = new Intent(this, MyActivity.class); 
intent.putExtra("key", list);
于 2013-03-07T00:13:18.070 回答
0

用于在and方法putExtra(String, Serializable)中传递值以检索数据。IntentgetSerializableExtra(String)

将 ArrayList> 从 Activity A 传递给 Activity B

Intent intent = new Intent(this, B.class);
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("sunil", "sahoo");
ArrayList<HashMap<String, String>> arl = new ArrayList<HashMap<String, String>>();
arl.add(hm);
intent.putExtra("arraylist", arl);
startActivityForResult(intent, 500);

检索活动 B 中的数据

ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("arraylist");
System.out.println("...serialized data.."+arl);
于 2015-01-12T11:25:51.100 回答