android application/activity life cycle: when should we save to flash?

时间秒杀一切 提交于 2019-12-10 10:58:26

问题


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..)..

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..


回答1:


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.




回答2:


You could implement Application class and use this callback



来源:https://stackoverflow.com/questions/5664314/android-application-activity-life-cycle-when-should-we-save-to-flash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!