0

I am making an android app and trying to figure out the best way to store the data. The data is fully static and will basically be several items with a name, logo and phone number for each.

The data will then be shown using a listview. So my question, what is the best way to store the data? Xml, json, SQLite or something else?

I want something that makes it easy to write down the data using Eclipse (like XML) but also easy to retrieve the data without the need to use a bunch of extra code.

user3658609
  • 539
  • 2
  • 6
  • 14

1 Answers1

0

If the data must last as long as the application session lasts, then caching them as JSON objects would be suitable. You could use GSON to quickly convert them to your JAVA model, but the objects also sound simple enough to parse using Android's out of the box JSONObject class. If the data must persist beyond the application's session, you can still store them in the SharedPreferences as JSON objects. I wouldn't use SQLite, because the data doesn't sound heavy & complex. The data sounds small & light enough for caching or SharedPreferences based on the data's persistence.

Ryhan
  • 1,815
  • 1
  • 18
  • 22
  • Where should I save the json file and how do I access it? – user3658609 May 22 '14 at 13:25
  • If you don't have your JSON data available as a string, you'll have to get the contents of your .json file as a string first using various java methods --> one of which can be found here http://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file .. Afterwards you can use androids JSONObject to parse the JSON into your JAVA friendly model, or have Google's GSON library do it for you. Your .json file can be placed in android's raw directory or assets directory I believe. – Ryhan May 22 '14 at 18:27