Android应用程序/活动的生命周期:我们什么时候要救闪烁?什么时候、应用程序、生命周期、Android

2023-09-06 05:25:37 作者:情话撩心

我有一个由许多活动的应用程序。每个活动可以修改以某种方式的项目。我节省这个项目通过序列几个对象,并将其保存到闪来闪。现在,如果用户离开应用程序,它可能是它获取由操作系统杀害。因此,我要在每一项活动在每一个的onPause()保存。

I have an app that is composed of many activities. Each activity can modify the project in some way. I'm saving this project to flash by serializing a few objects and saving them to flash. Now, If the user leaves the app, it's possible that it gets killed by the os. Therefore, I should save at every onPause() on every activity..

但是,这是非常愚蠢和消费(连载,打开文件,覆盖文件..)..

But this is very stupid and consuming (serialize, open file, overwrite file..)..

你有什么更好的主意?顺便说一句,如果我不希望使用数据库来保存我的项目是对象序列化不够好,或者我应该使用的东西更强大的(XML?)?

Do you have any better idea? By the way, if I don't want to use a Database, to save my projects is object serialization good enough or should I use something more robust (xml?) ?

有关的澄清和建议,谢谢..

Thanks for the clarifications and suggestions..

推荐答案

我保存在每一个的onPause和每一个onResume恢复。这prevents有些古怪的地方,如果你有堆栈上的同一个活动的倍数。

I save at every onPause and restore in every onResume. This prevents some oddities if you have multiples of the same activity on the stack.

大多数谷歌应用程序做到这一点为好,或者保存到中间位置,如果你想提示输入正常储蓄。

Most Google apps do this as well, or save to an intermediate location if you want to prompt for saving normally.

如果它不是导致性能问题,并符合对维护您的要求那么它可能不够好。

If it's not causing performance issues and meets your requirements for maintainability then it's probably good enough.