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

2

11

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?

Star answered 15/6, 2013 at 0:40 Comment(7)
Depends on the data. Does "medium to large" refer to the total volume of data or the number of records, or both?Originative
@Originative : this "medium to large data" that i mentioned was refer to the number of records of data, thus, it varies also to its volume as it expands the data records. sorry for making it vague. :)Star
In your case I would suggest going with SQLite as it can be use to retrieve easily compared to File Storage. And Shared Preferences is usually meant for saving preferences and I personally think it shouldn't be used in your case. Also if you use file storage you will need to process more things manually. So I think SQLite is the best solution out of your options.Electronic
@Milanix : Thank you for your quick response. Your suggestion would much appreciated :). I also think that matter since then. Shared Preferences for this part has a long way to deal with this. I wonder, in terms of speed profiling in retrieving data, which is better? File storage or SQLite database?Star
For retriving data i.e; sorting, ordering, you should mostly use database.Take an example of simple dictionary app one has database implementation and other has file. Let's search for "stack" if we have a file, we need to get all data from file into an arraylist and iterate through each items in the list to check in that item contains stack. But, if we have an database we can simply say select * from '_table' where '_word'="stack" and get back cursor that contains exactly what you want.Electronic
@Milanix : Yeah, that's also true. For SQLite database, its simply just dealing with SQL commands while for File storage, you have to deal with its algorithm code to satisfy its output.Star
Related: What is the advantage of Using SQLite rather than File? and Android Performance : Flat file vs SQLiteTercentenary
P
10

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

Prophetic answered 15/6, 2013 at 4:39 Comment(0)
C
7

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

Crossman answered 15/6, 2013 at 3:50 Comment(3)
The comparison of SQLite Database and Shared Preferences are mostly concluded. However, I want to know also on File System part on how to make deal its data, considering on saving, its speed and efficiency.Star
@Star : Since you have a decent amount of data saving it in the file system would probably have poorer performance than the database. In order to access a piece of data you would need to load the file and parse it until you found the data you are looking for. If it needs edited, you would need to make the change and then resave the file.Crossman
So by that means, it's just something to manipulate the file in and out, permission to read, write and/or execute. This particular matter will have a lot way to do. :)Star

© 2022 - 2024 — McMap. All rights reserved.