Android的 - 如何通过的HashMap<字符串,字符串>活动之间?字符串、HashMap、Android、GT

2023-09-12 03:21:17 作者:动我女人者全撂倒

如何通过详细信息的HashMap到另一个活动?

 的HashMap<字符串,字符串>详细=新的HashMap<字符串,字符串>();
detail.add(姓名,帕雷什);
detail.add(姓,mayani);
detail.add(手机,99999);
......
......
 

解决方案

这是pretty的简单,所有集合对象实现Serializable接口(SP?)接口,这意味着它们可以在被作为附加功能意图

腾讯Android高工面试 为什么要使用SparseArray和ArrayMap替代HashMap

使用 putExtra(字符串键,序列化OBJ)插入的HashMap 和其他活性的研究使用 getIntent()。getSerializableExtra(字符串键),您需要将返回值转换为的HashMap 虽然

How to pass the detail HashMap to another Activity?

HashMap<String,String> detail = new HashMap<String, String>();
detail.add("name","paresh");
detail.add("surname","mayani");
detail.add("phone","99999");
......
......

解决方案

This is pretty simple, All Collections objects implement Serializable (sp?) interface which means they can be passed as Extras inside Intent

Use putExtra(String key, Serializable obj) to insert the HashMap and on the other acitivity use getIntent().getSerializableExtra(String key), You will need to Cast the return value as a HashMap though.