Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving data on Android : File Storage vs SQLite Database vs Shared Preferences

This title makes me wonder on what is most suited feature in saving medium to large data on a specific application. I know there is a recent questions that i have seen on Stackoverflow regarding on saving data with these feature but I want to know, as what i have said, what suited most. Do you have any suggestion regarding to this?

like image 959
stryker Avatar asked Jun 15 '13 00:06

stryker


People also ask

Which one is better shared preferences and SQLite?

To give an example, SharedPreferences are useful for storing user preferences, where there are just a handful of variables that need storing. SQLite on the other hand would be better for storing data where there is a large set of items, such as song titles in a music library which need to be searched through.

Why SQLite database is a better option of storing the data?

sqlite packages offer a higher-performance alternative where source compatibility is not an issue. There is no file parsing and generating code to write and debug. Content can be accessed and updated using powerful SQL queries, greatly reducing the complexity of the application code.

What are the advantages of using shared preferences over save instance state?

Shared preferences allow you to store small amounts of primitive data as key/value pairs in a file on the device. To get a handle to a preference file, and to read, write, and manage preference data, use the SharedPreferences class.

What is the difference between internal storage and shared preferences?

Shared Preferences. Store private primitive data in key-value pairs. Internal Storage. Store private data on the device memory.


2 Answers

Shared Preferences is better for things like settings or small amounts of data. Data stored in the Shared Preferences is stored in key-value pairs. This makes retrieving the data simpler, but there is not a really efficient way to query/search for a specific piece of data.

The database is an implementation of SQLite. This is useful when there is a large amount of records to store that all have the same/similar fields. Since it is SQLite, you can write queries to get specific records from the tables.

I do not have as much experience saving to the file system for storage, so someone else will have to speak to that one.

Here is a link to another stackoverflow discussion that compares SQLite and Shared Preferences. Pros and Cons of SQLite and Shared Preferences, as well as to the Android Documentation that goes into more details about how each method works. http://developer.android.com/guide/topics/data/data-storage.html

like image 99
JFeather Avatar answered Oct 13 '22 02:10

JFeather


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.

as per official Website

like image 22
Tarsem Singh Avatar answered Oct 13 '22 03:10

Tarsem Singh