tags:

views:

71

answers:

2

I'm getting hung up on how to handle the data for an app I'm designing. I want to pull a list of items from the net. The data is updated routinely, and I think it would be good to store all the data on the device so the app can load quickly and refresh the data in a background thread rather than have to wait for the network on every start-up.

I think I should make the data available in an XML and have a thread parse and save into a SQLite DB, but I'm not sure if that's the "best practice." Are there other ways that people go about handling this?

+1  A: 

Sounds reasonable.

If the download of the new data takes more than some seconds, you might want to use a Service. This will allow you to continue the update even when the user has left your app.

Also, think about how you will notify the user that something is going on. Displaying some progress indicator is always a good idea. Otherwise, users might just think the data is not up to date because the app is broken.

Julien
That's not a bad way to go, I was planning on having some kind of "refreshing..." line at the top of the screen while it is updating. But I'm actually trying to work out the intricacies of providing the data (an XML or JSON file?) and storing it on the device.
ASTX813
Well XML or JSON is mostly a matter of personnal preference and which one is the easier to implement on your server. They both have good API support on Android.To store the data on the device, Thomas' response on using a ContentProvider is probably the best way to go if you want a clean design.
Julien
A: 

The cleanest way (or at least, I think it is the cleanest way) is to implement a custom ContentProvider class that interfaces with your server. You can query the contenprovider and if it doesn't have the data in a local cache (for example a SQLite db as you said) it downloads it from your server and adds it to the local data. Why a content provider? because then you can easily access your data across apps and you have a nice and clean way to get your data when using intents. Also, I personally prefer not to download data when the app is not running, because it will cost battery life while the user does not actively requests the data.

Thomas Vervest