Reputation: 18120
I need persistent storage for my application for a certain activity. I was going to initially use a database table with 5 columns for holding the data I needed, but then I thought that maybe using sharedPreferences may be lighter weight in this case. So my question essentially is, if I am going to use a database for a single entry, should I just use sharedPreferences because I know databases are known for being a bit heavy.
Upvotes: 1
Views: 659
Reputation: 26007
If you just want to store the 5 values, then using SharedPreference
might be preferable. It is also faster than using database. In addition to allow persisting key-value pairs, SharedPreference
also supports saving sets
and ArrayList
.
See Save ArrayList to SharedPreferences. So storing an array in the ShraredPrefernce
will suffice.
If you have more structured data, then using database might be better to manage. To know more about when SharedPreference
would be good to use and when SQL Lite
database, Pros and Cons of SQLite and Shared Preferences question is a good read. Hope this helps.
Upvotes: 2
Reputation: 2470
Yes, sharedPreferences works great for what you are trying to do. It's lightweight and needs the least amount of code to meet your requirement.
Upvotes: 1