Possible Duplicate:
Android: Saving a state during Android lifecycle
i want to save some values in a file before the user terminates the activity.In which method should i implement this?
Apart from using a file , or sql lite is there a way of storing complex data such as a layout (that has dynamically changed ) ?
"onDestroy() Note: do not count on this method being called as a place for saving data!"
Layouts are bound to the context of the Activity that holds it, so you do no want to save full View
objects to files because the Activity that it's attached to is void.
The easiest method (depending on the amount and type of data you want to save) is using the SharedPreferences library. It's a file I/O wrapper that makes saving and retrieving data pretty simple. You can save the specific layout data in the onPause()
method, the rebuild the layout with the specifications in onResume()
.
If the data you need is too complex for SharedPreferences
, you'll have to save it to use other methods for saving (found in that link). The process for rebuilding the layouts will be the same.