MonoDroid的:活动之间共享不平凡的数据 [英] MonoDroid: Sharing non-trivial data between Activities

查看:92
本文介绍了MonoDroid的:活动之间共享不平凡的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据,多个活动需要操作。基本上有就是挂关闭它有一个只读的屏幕和多个编辑屏幕。

I have some data that multiple Activities need to manipulate. Basically there is one read-only screen and multiple edit screens that hang off it.

起初我认为传递数据的意图字符串参数,但如果用户$ P $编辑字段这些更改将丢失后psses后退按钮。

At first I considered passing the data as a string parameter on the intent, but if the user presses the back button after editing a field those changes would be lost.

那么,什么是在不同的活动共享数据recomended方法是什么?如果我只是每一页转换之前将其保存到临时文件?

So what is the recomended way to share data across the different Activities? Should I just save it to a temp file before each page transition?

推荐答案

要做到这一点,最简单的方法可能是将对象存储在一些全球可用的地方,比如你的应用程序的应用程序对象(创建一个,如果有ISN 't的一不已,当然)。这可能要么是静态或实例,这取决于你想要它如何工作。

The easiest way to do this is probably to store the object in some globally available place, such as on the Application object for your app (creating one if there isn't one already, of course). This could either be static or instance, depending on how you want it to work.

另一个选择是序列化对象到某种字符串重新presentation(XML,JSON等),传递到下一个活动,和反序列化的另一面。这会工作,但肯定是有点重了。

Another option is to serialize the object down to some sort of string representation (XML, JSON, etc), pass that through to the next activity, and deserialize it on the other side. This would work, but is definitely a bit heavier.

这篇关于MonoDroid的:活动之间共享不平凡的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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