关于共享首选项(About Shared Preferences)

编程入门 行业动态 更新时间:2024-10-20 11:36:35
关于共享首选项(About Shared Preferences)

我正在寻找存储用户数据的最佳方式,例如(IP地址,端口号,用户名,密码)以保证活动的有效性。

所以我决定去使用SharedPreferences。 在提到这个例子时,我看到一个答案是“如果用户清除应用程序数据:

设置 - >应用程序管理器 - >您的应用程序 - >清除数据

然后保存在共享首选项中的所有数据都将被删除

这是真的? 请帮我解决一下这个。 我提到开发人员指南,但没有提到用户可以清除共享首选项数据。

这是做这件事的好方法吗? 或者还有另一种更好的方法来获得它?

I'm searching for the best way to store user data like (IP address, Port number, username, Password) for life time of activity.

So I've decided to go use SharedPreferences. While referring this example I saw one answer which is "if user clear the application data from:

setting -> application manager -> your application -> clear data

Then all data saved in shared preferences will get removed

Is this true? Please help me with this. I referred developer guide but its nowhere mentioned that user can clear Shared Preferences data.

Is this a good way to do this? Or there is another better way to get it?

最满意答案

如果用户通过设置清理数据,那么它是完全真实的,那么共享首选项中的所有数据都会消失

Android为您提供了几个选项来保存持久的应用程序数据。 您选择的解决方案取决于您的特定需求,例如数据是否应该专用于您的应用程序或可供其他应用程序(和用户)访问以及数据需要多少空间。

您的数据存储选项如下:

共享首选项将私有原始数据存储在键值对中。

内部存储将私人数据存储在设备内存上。

外部存储将公共数据存储在共享外部存储上。

SQLite数据库将结构化数据存储在私有数据库中。

网络连接使用您自己的网络服务器将数据存储在网络上。

Android为您提供了一种方式,让您甚至可以将您的私人数据公开给其他应用程序 - 包括内容提供商。 内容提供者是一个可选组件,它公开对您的应用程序数据的读/写访问权限,受到您想强加的任何限制。 有关使用内容提供者的更多信息,请参阅内容提供者文档。

Yes its totally true if user clean data through setting then all the data in shared preference will get vanished

Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires.

Your data storage options are the following:

Shared Preferences Store private primitive data in key-value pairs.

Internal Storage Store private data on the device memory.

External Storage Store public data on the shared external storage.

SQLite Databases Store structured data in a private database.

Network Connection Store data on the web with your own network server.

Android provides a way for you to expose even your private data to other applications — with a content provider. A content provider is an optional component that exposes read/write access to your application data, subject to whatever restrictions you want to impose. For more information about using content providers, see the Content Providers documentation.

更多推荐

本文发布于:2023-08-06 23:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首选   Shared   Preferences

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!