0

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

Community
  • 1
  • 1
jsp
  • 2,546
  • 5
  • 36
  • 63

1 Answers1

2

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

Moog
  • 10,193
  • 2
  • 40
  • 66
  • Also, depending on the image, you could store the URI/URL as a string to point at it when you resume the activity. – Ashterothi Jul 29 '11 at 18:53
  • @Merlin: Is there an advantage of using shared preference over global variables ?? – jsp Jul 29 '11 at 20:59