SQLite的优缺点和共享偏好 [英] Pros and Cons of SQLite and Shared Preferences

查看:176
本文介绍了SQLite的优缺点和共享偏好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQLite数据库和共享首选项之间存储信息的好机制是什么?

What is the good mechanism to store information among SQLite database and Shared Preferences?

为什么要使用共享首选项?为什么要使用sqlite?我试图找到他们之间的区别,这是更好的数据存储机制,但我无法找到适当的答案在谷歌。请帮助我的示例和解释。

Why use shared preferences? Why use sqlite? I tried to find the difference between them, and which is the better mechanism for data storing, but I am unable to find the appropriate answer on Google. Please help me with example and explanations.

推荐答案

这真的取决于你想要存储的数据。

It really depends on the data you want to store.

SQLite

大量相同的结构化数据应存储在SQLite数据库作为数据库设计用于这种数据。由于数据由数据库构造和管理,因此可以使用查询语言(如SQL)查询匹配某些标准的数据子集。这使得可以在数据中进行搜索。当然,管理和搜索大量数据会影响性能,因此从数据库读取数据可能比从SharedPreferences读取数据更慢。

Large amounts of same structured data should be stored in a SQLite database as databases are designed for this kind of data. As the data is structured and managed by the database, it can be queried to get a sub set of the data which matches certain criteria using a query language like SQL. This makes it possible to search in the data. Of course managing and searching large sets of data influences the performance so reading data from a database can be slower than reading data from SharedPreferences.

SharedPreferences

SharedPreferences是一个键/值存储库,您可以在某个键下保存数据。要从商店中读取数据,你必须知道数据的关键。这使得读取数据非常容易。但是容易存储少量的数据是困难的,它是存储和读取大型结构化数据,因为你需要定义每个单一的数据的关键,此外,你不能真正搜索数据中,除了你有一个特定的概念命名键。

SharedPreferences is a key/value store where you can save a data under certain key. To read the data from the store you have to know the key of the data. This makes reading the data very easy. But as easy as it is to store a small amount of data as difficult it is to store and read large structured data as you need to define key for every single data, furthermore you cannot really search within the data except you have a certain concept for naming the keys.

这篇关于SQLite的优缺点和共享偏好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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