0

I am developing an app that is meant to be offline most of the time. It connects to a server, grabs some data in XML format, and then uses that data throughout the remainder of the app's existence. The data is periodically updated manually.

This data is used for populating ListViews and putting information into dynamically created activities. I've been accessing and using the XML file directly up until now but it's kind of a pain to work with. It just feels kind of clunky and wrong.

My question is more about workflow than anything else. Is there a smarter way to do this? Should I leave this data in XML format and just parse though it every time I need it, or should I convert this XML over to SQLite upon initial download or something?

There's obviously no one right answer here.. but I am fairly new to Java/Android in general and I am interested in hearing what other solutions might work better for this.

Any tips?

cowsay
  • 1,282
  • 1
  • 15
  • 36
  • `The data is periodically updated manually.` ?? By who? Server? User? How? Manually? – greenapps Jul 15 '14 at 19:45
  • If all works as you want there is no reason to add more code. Unless it is slow and you think you could speed up the app using a database. – greenapps Jul 15 '14 at 19:47

2 Answers2

0

If the xml isn't very huge then you can save it in the cache folder of your app and parse data from there every time it's requested.

If it's huge then you can keep it on SD Card and parse data from there every time it's requested.

In both the cases you can parse the xml data and put it inside your SQlite if it suits you. Also when you get an updated version delete the older one if not required.

CodeWarrior
  • 5,026
  • 6
  • 30
  • 46
  • Thank you for letting me know about the cache folder. I've been sticking it in assets but cache makes more sense. It's not huge by any means. I'm only using small samples of data right now but I don't expect the files to be any larger than maybe 50-100KB at the end of the day. Is putting into SQLite a decent solution then? I don't expect performance to be an issue accessing the XML files directly since they're so small .. but I'm trying to make the rest of the coding easier on myself. It takes quite a lot of code to parse through an XML file. – cowsay Jul 15 '14 at 19:45
  • @user1003916 Yes in that case putting values in your database would be easier. Performance won't be an issue. – CodeWarrior Jul 15 '14 at 19:53
0

Why not use the SharedPreferences class to store this information? There are many posts that describe how to do this.

Android: Save array to app data

Array/Data Storage Options

How to use SharedPreferences in Android to store, fetch and edit values

Community
  • 1
  • 1
Luke
  • 93
  • 5