Reputation: 17
I'm designing an app which uses information about shops in my city (only in my city as a first step), information I already know so I would be able to create the full database during the development. I could add new shops to the database but it would be like once every six months, so I consider it as static. The user don't need to update it and the size would reach hundreds of rows, but not a huge amount of them.
I don't know which is the best way to store it, as I come from a large period of Javascript programming I feel comfortable with JSON or XML, but looks like Android apps mostly use SQLite and I want to do it in the proper way. I would like to know also which would be the best option if I wanted to update the database externally with more frequence.
Which is the best way to store static data like I described?
Upvotes: 0
Views: 217
Reputation: 1647
Usually in Android there is 3 ways to store data for small data like application settings, user preferences (key -> value stuff) one would use SharedPreferences
but i think in your case it won't apply,
the other two are Files and SQLite for your case i would go with SQLite, you could store the database in JSON or XML and process it each time the application starts but that would be an unnecessary extra processing overhead (even when doing in a background thread it would be unnecessary) and memory waste so i would go with the SQLITE approach altought its more work in the long run it pays off
(later if the data is to be presented in ListViews
and so on you could even take advantage of android ContentProvider
and to sync data you could combine that with a SyncAdapter
for your update the database externally question), also if
So long story short my advice is go with SQLite
approach
Upvotes: 2
Reputation: 3658
You could do it with a JSON file which you'd put under the res/raw directory an then read it like this when you need it.
However, if you want to do queries on this, it would be more advantageous to put it in a database. Otherwise you'd have to keep a lot of info in memory (depending on the structure/amount of the data of course) which is a big no-no on mobile.
Upvotes: 0