活动之间共享域对象 [英] Sharing domain objects between activities

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

问题描述

我写我的应用程序逻辑域对象(以使多用户界面和移植到其他平台),和我现在lookng在执行活动的用户界面。

I have written my application logic in domain objects (to enable multiple user interfaces and porting to other platforms), and am now lookng at implementing Activities for the user interface.

考虑到每个活动需要序列化的状态,有什么保证我的域对象的最佳方法只序列化一次?

Considering that each activity needs to serialise its state, what is the best way to ensure my domain objects are only serialised once?

推荐答案

如果你谈论的是序列化的对象活动之间的共享,你应该创建自己的 应用程序 并存储在那里,你的共享状态。一个应用程序对象是所有的活动在您的应用程序,这使得它存储的非持久的状态下完美的地方共享。你可以在应用程序通过调用的 getApplication()方法 你的活动服务

If you're talking about Serialising object to share them between Activities you should create your own subclass of Application and store your shared state in there. A single Application object is shared by all the Activities in your app which makes it the perfect place to store non-persistent state. You can get to the Application by calling the getApplication() method on your Activity or Service.

您需要在指定您的自定义类的<应用> 标签的的Andr​​oidManifest.xml 文件。

You'll need to specify your custom class in the <application> tag of your AndroidManifest.xml file.

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

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