Laura
Laura

Reputation: 2773

Android SharedPreferences or SQLite Storing

I have a question. In my project I have some user preferences which are stored in the SQL database. There are about 200 records and the table has 3 columns. This records do not change, only if the user is changed and the data is downloaded again. I want to put them in SharedPreferences because it would be easier to manipulate the code. The way it is now, it's a bit difficult as I make the queries asynchronous. Now, my question is: Is the number of records to large for SharedPrefrences? Or it should be no problem to store them there?

Upvotes: 2

Views: 4604

Answers (1)

Ronak Mehta
Ronak Mehta

Reputation: 5979

Shared Preferences:

All shared prefs are stored in /data/data/[package name]/shared_prefs/[app name].xml, so i think there's no limit based on aechitecture.

Shared Preferences is nothing but a simple table which has two columns. (key, value).

Shared Preference size 8192 characters according to this documentation: http://developer.android.com/reference/java/util/prefs/Preferences.html#MAX_VALUE_LENGTH

advantages:

  • Fast retrieval
  • Easy to understand and program

disadvantages

  • Maintaining Keys are difficult if we store a lot of values.
  • User can clear this at any time.

Database:

When we have a lot of values to store with complex structure, we are left with only one great solution, ie. DB.

advantages

  • We can maintain structure of data.
  • Android has nice and simple APIs to handle sqlite operations.

disadvantages

Operation is little bit slow comparing to shared preferences. user can clear this at any time.

Reference

Upvotes: 5

Related Questions