Android的UI活动的持久性 [英] Android Activities UI Persistence

查看:207
本文介绍了Android的UI活动的持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有一个Android应用程序,可以相互间切换UI的持久性两项活动如下:

I need to have two activities in an Android app that can be switched between each other with UI persistence as follows:

  1. 活动一推出b活动。

  1. Activity A launches Activity B.

用户触发b活动的一些用户界面的变化。

User triggers some UI changes in Activity B.

b活动返回到活动A(通过调用 onBack pressed()或类似的东西)

Activity B returns to Activity A (by a call to onBackPressed() or something similar)

活动进行重新启动b活动。

Activity A re-launches Activity B.

我想在步骤2中所做的更改可见在步骤4。

I would like the changes made in step 2 to be visible in step 4.

我用b活动上的 singleInstance 活动标签无济于事都试过了。我也preFER一个更优雅的解决方案不是简单地编写所有对象的属性到一个文件或SQLite表。 看来,这种行为必须容易实现鉴于Android的自动会为呼叫 onBack pressed(),其中母公司活动的UI被保存。

I have tried using the singleInstance activity tag on Activity B to no avail. I would also prefer a more elegant solution than simply writing all object properties to a file or SQLite table. It seems that this behaviour must be easily achievable given that Android does it automatically for calls to onBackPressed() where the parent Activity's UI is saved.

任何帮助是非常AP preciated。

Any help is much appreciated.

推荐答案

如果你想坚持的多个活动之间的数据,最好创建应用程序的一个子类,并把你的目标在那里。然后,每个活动,你可以产卵弄个相同的对象。

If you want to persist data between multiple activities it's best to create a subclass of Application and put your objects in there. Then each activity you spawn can get hold of the same objects.

http://developer.android.com/reference/android/app/ Application.html

<一个href="http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables">http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables

这篇关于Android的UI活动的持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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