Android - 如何传递 HashMap<String,String>活动之间? [英] Android - How to pass HashMap<String,String> between activities?

查看:26
本文介绍了Android - 如何传递 HashMap<String,String>活动之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将detail HashMap 传递给另一个Activity?

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");
......
......

推荐答案

这很简单,所有Collections对象都实现Serializable (sp?) interface 这意味着它们可以在 Intent

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

使用 putExtra(String key, Serializable obj) 插入 HashMap 并在另一个 Activity 上使用 getIntent().getSerializableExtra(String key),您需要将返回值转换为 HashMap.

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

这篇关于Android - 如何传递 HashMap&lt;String,String&gt;活动之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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