在选项卡上保存数据
我有 3 个选项卡,每个选项卡都有一个单独的活动。我想在用户单击任一选项卡上的“保存”时保存数据。有几个选项可供选择;共享首选项、全局变量或将对象保存在上下文中。
编辑:我必须保存图像&文本字段
对于选择哪种方法有什么建议吗? 谢谢
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
Store Objects in ApplicationContext
Any suggestions on which method to pick ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这完全取决于您希望存储它们的时间长度。
应用程序结束后,存储在应用程序上下文中不会保留数据。它只是存储在内存中。
您的字符串数据可以使用共享首选项,但图像数据需要进行一些操作,并且可能有其他限制,例如数据大小 (TBC)。
请查阅相关数据存储的SDK文档
最便捷的方式是将文本保存在共享首选项中并将图像保存到磁盘。如果要存储在应用程序目录中,请参考 getDir() 函数
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