问题
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