共享首选项与数据库 [英] Shared Preferences vs Database

查看:62
本文介绍了共享首选项与数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据是简单的属性值,因此我可以用任何一种方式进行存储,但是我想知道哪种方法更可靠?共享的首选项是否自动保存并因此更可靠?还是因为它们是非事务性的,难道不是那么可靠吗?

My data is simple property values so I could store either way, but I was wondering which is more reliable? Are shared preferences auto saved and therefore more reliable? Or because they are non-transactional is that less reliable?

推荐答案

SharedPreferences或ContentProvider/SQLite数据库的使用是基于情况的.根据您的情况,我建议使用 SharedPreferences . SQLite数据库用于潜在的数百个条目.还可以查询SQLite数据库,并且数据检索更加健壮. SQLite数据库为您的条目增添了巨大的力量.但是根据您的情况,除非您非常需要对属性值进行排序/过滤,否则我建议您使用SharedPreferences.它们都是可靠的服务,SharedPreferences不会自动保存,必须使用commit()保存更改. SQLite数据库的结构比SharedPreferences多得多.有关更多信息,请查看文档.

The use of SharedPreferences or a ContentProvider/SQLite database is situation-based. In your situation, I would recommend using SharedPreferences. A SQLite database is meant for potential hundreds of entries. SQLite database can also be queried and the data retrieval is much more robust. The SQLite database adds immense power to your entries. But in your case, I would recommend using SharedPreferences, unless you have the unusual need to sort/filter through your property values. They are both reliable services, SharedPreferences are not autosaved, you must use commit() to save changes. The SQLite database is a lot more structured than SharedPreferences. For more information check out docs.

这篇关于共享首选项与数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆