saving data on tabs

故事扮演 提交于 2019-12-04 06:07:05

问题


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

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