Dinesh Kannan
Dinesh Kannan

Reputation: 1255

android choosing local storage ( files vs database)

i would like to know when to use database and when to use file storage for storing list of primitive data types in android for fast access.

for example the data will be a set of strings.

name:xxx , emailid:yyy

name:zzz , emailid:eee

Upvotes: 0

Views: 323

Answers (4)

XGouchet
XGouchet

Reputation: 10203

Based on your question, if you need to store a lot of similar data (eg : name and email for many contacts), then using a database is the best choice.

SharedPreferences should be used for exactly that : preferences (eg: tuning your application's behavior, appearance, ...)

Upvotes: 0

Miguelost
Miguelost

Reputation: 59

If you want store key:value info, use sharedpreference. But if is a long amount of data (just like 1.000.000 key:value data) maybe you need use a database.

I recommend to use a greenDAO database for android proyects.

Upvotes: 0

Terry
Terry

Reputation: 14867

If you want to store key-value pairs, there is something even simpler than storing it in a file or database: SharedPreferences.

You can look up the usage here: http://developer.android.com/training/basics/data-storage/shared-preferences.html

And a great tutorial you find here: http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html

Upvotes: 0

Buda Gavril
Buda Gavril

Reputation: 21637

If you need to query your data, to show them in a list or if you have many kvp items, I would suggest to use a database(you can query your data without loading all the items, use them with cursor adapter with list, etc). But if you will have only 2-3 kvp's, you can store them in shared preferences.

Upvotes: 1

Related Questions