Android的 - 路过的HashMap意图通过 [英] Android - passing hashmap through intent

查看:177
本文介绍了Android的 - 路过的HashMap意图通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个意图通过自定义对象的HashMap中。

I'm trying to pass a Hashmap of custom objects through an intent.

我想使用parcelable因为这就是我读的是做事的Andr​​oid(即parcelable了序列化)的正确方法。

I am trying to use parcelable as that's what i read is the correct way to do things in android (i.e. parcelable over serializable).

然而,当我尝试使用getParcelable得到HashMap的,它无法找到我的意图是HashMap,但getSerializable可以了。

However, when i try and get the hashmap using getParcelable, it can't find my hashmap in the intent, but getSerializable can.

是否确定使用序列化的包含HashMap?这是我唯一的选择吗?

Is it OK to use serializable for hashmaps? Is this my only option?

推荐答案

当然,您可以序列化的地图,只要你的对象是可序列。什么,你也可以做的就是创建一个保存数据的独立单身类(数据存储或这样吗?)。这样,您就不需要从活动数据传递到活动。或者,更简单,保存在一个公共静态变量的数据。

You can of course serialize your map, as long as your Objects are serializable. What you also could do is creating a separate singleton class (DataStore or so?) that saved your data. This way you don't need to pass the data from Activity to Activity. Or, even simpler, save the data in a public static variable.

这篇关于Android的 - 路过的HashMap意图通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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