Android的UI活动的持久性持久性、Android、UI

2023-09-12 05:47:27 作者:爱我你就啪啪我^3

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

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

活动一推出b活动。

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

http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables