在选项卡上保存数据

发布于 2024-11-27 04:12:19 字数 381 浏览 1 评论 0原文

我有 3 个选项卡,每个选项卡都有一个单独的活动。我想在用户单击任一选项卡上的“保存”时保存数据。有几个选项可供选择;共享首选项、全局变量或将对象保存在上下文中。

编辑:我必须保存图像&文本字段

Android 共享首选项

在 ApplicationContext 中存储对象

对于选择哪种方法有什么建议吗? 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咆哮 2024-12-04 04:12:19

这完全取决于您希望存储它们的时间长度。

应用程序结束后,存储在应用程序上下文中不会保留数据。它只是存储在内存中。

您的字符串数据可以使用共享首选项,但图像数据需要进行一些操作,并且可能有其他限制,例如数据大小 (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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文