什么是Android上的最佳实践,以保持活动deathes /重新启动之间的数据为整个应用程序会话? [英] What is the best practices on Android to keep data between activities deathes/restarts for the whole application session?

查看:292
本文介绍了什么是Android上的最佳实践,以保持活动deathes /重新启动之间的数据为整个应用程序会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在设计一个Android应用程序,具有工作在喜欢的方式向导几项活动 - 用户应通过从活动#1至#活动5去的最后一个活动(#6)

因为我们知道一个活动可以在我们使用Application类作为一个静态存储保持的向导活动和其他数据我们的应用程序需要整个会话数据的用户输入,低内存突然终止操作系统。

不幸的是,我们已经发现这种方法失败 - 看起来像应用程序类的实例也可以通过OS杀死(这是一个特别发现在Android 1.6与1.5)。是我们的预期错了这种方法(我们认为应用类的实例总是生活在整个应用程序会话)?

所以,问题是 - 什么是Android上的最佳实践,以保持活动deathes之间的数据/重新启动整个应用程序会话

解决方案
  

我们正在设计一个Android应用程序,   有几个活动,这是   工作在这样的方式向导 - 用户   应该通过从活动#1   活动#5到到达最后的   活性(#6)。

你确定你要实现它们作为单独的活动?为什么不是一个单一的活动,使用 ViewFlipper 或东西向导状态之间移动?

  

是我们的预期错了这   方法(我们认为应用程序类   比如一直住整个   应用程序会话)?

Application类的实例并永远活在整个应用程序会话,AFAIK。一旦所有的活动都被破坏,但是,应用程序也将被销毁。

  

所以,问题是 - 什么是最好的   Android上的做法,以保持数据   活动deathes /重启之间   为整个应用程序会话?

  1. 使用一个服务 - 如果被踢出内存,刚开始超过从无到有
  2. 使用数据库
  3. 使用的文件

或者,最好的:不要在这种情况下,使用多个活动。向导是一个顺理成章的事情;把它看作把它变成一个单一的活动。通过的onSaveInstanceState坚持你的状态(),和你设置。

We're designing an Android app that has several activities which are working in a wizard like way - user should pass from the activity #1 to activity #5 to get to the final activity (#6).

Since we know an activity can be suddenly terminated by OS on low memory we used Application class as a static storage for keeping the data the user inputs on "wizard" activities and other data our app needs for the whole session.

Unfortunately we've discovered this approach fails - looks like the Application class instance is also can be killed by OS (this was specifically discovered on Android 1.6 versus 1.5). Are our expectations wrong on this approach (we think Application class instance always lives for the whole app session)?

So the question is - what is the best practices on Android to keep data between activities deathes/restarts for the whole application session?

解决方案

We're designing an Android app that has several activities which are working in a wizard like way - user should pass from the activity #1 to activity #5 to get to the final activity (#6).

Are you sure you should be implementing them as separate activities? Why not a single activity, using ViewFlipper or something to move between the wizard states?

Are our expectations wrong on this approach (we think Application class instance always lives for the whole app session)?

The Application class instance does always live for the whole app session, AFAIK. Once all your activities are destroyed, though, the Application will be destroyed as well.

So the question is - what is the best practices on Android to keep data between activities deathes/restarts for the whole application session?

  1. Use a Service -- if this gets kicked out of RAM, just start over from scratch
  2. Use a database
  3. Use a file

Or, best: don't use multiple activities in this case. A wizard is a single logical thing; treat it as such and make it be a single activity. Persist your state via onSaveInstanceState(), and you're set.

这篇关于什么是Android上的最佳实践,以保持活动deathes /重新启动之间的数据为整个应用程序会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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