问题
I have 3 tabs, each a separate activity. I want to save data when user clicks save on either of the tabs. There are couple of options available; shared preference, global variables or saving the objects in context.
EDIT:I have to save an image & textfield
Android Shared Preferences
Store Objects in ApplicationContext
Any suggestions on which method to pick ? thanks
回答1:
That is entirely dependent upon the length of time you wish to store them for.
Storing in the Application Context will not persist data after the application has ended. It just stores in memory.
Shared preferences is a possibility for your string data but image data would require some manipulation and may have other restrictions for example size of data (TBC).
Please consult the relevant SDK documentation on Data Storage
The most convenient way would be to save the text in shared preferences and the image to disk. Refer to the getDir() function if you want to store in the application directory
来源:https://stackoverflow.com/questions/6877416/saving-data-on-tabs