Recommendations for persisting data on Android?

There is a web service that provides some data that my app makes use of. This data is fairly large and only changes VERY infrequently so I thought it would be nice if the app could cache it on the SD Card and only update it as needed.

Currently I'm grabbing the data (an XML file) and parsing it into an object tree using SAX. This process takes (at most) 2-3 seconds over my WIFI. However, serializing the resulting objects to the SDCard takes significantly longer (a minute or more) and deserializing it still takes longer than just download/parsing in the first place.

Does anyone have any recommendations for improving this or alternate ideas for persisting this data (other than just saving the XML file and reparsing every time)?

UPDATE: This is more than a trivial collection of records. The object-graph is actually ridiculously complex and storing it into a database would result in dozens of tables with only a single record in each one.

Asked by: Lenny173 | Posted: 25-01-2022

Answer 1

Android serialization is notoriously slow. I highly suggest switching to using XML or JSON (or whatever) and writing the file out that way. Since you've already got an XML parser, it may make the most sense just to cache the original XML file you downloaded and reparse it as necessary.

I have switched from Serializable to JSON file storage in an app before and the speed increase was incredible, at least one order of magnitude.

(I may be misunderstanding your question - I assume you are using Serializable for writing to the disc. If you are reproducing the XML, then I'm not sure why it is so much slower on the SD card. Also, I agree that the SQLite database makes the most sense typically, but as you've already stated it does not fit the needs of your application.)

Answered by: Marcus168 | Posted: 26-02-2022

Answer 2

Also unless your data is at least 100s of Kb, I would suggest just storing it in your private data storage instead of on the SD card. Keep in mind that you can't rely on the SD card being available.

Answered by: Miller975 | Posted: 26-02-2022

Answer 3

I've just been writing an android application for the last week which basically does this. It fetches some (large) XML file online, and then displays part of the data in various views.

We do it by fetching and parsing the XML using SAX, and (while parsing) writing it all to a SQLite database. And then we are just querying the database each time we need to display some view of the dataset.

Works like a charm, and is fast enough for displaying a lot of data on a google map overlay, where we are querying the database on every single call to the draw method of our map overlay.

So I would definitely suggest going for a SQLite database, if the data in the XML document is easily represented in a database.

Answered by: Emily154 | Posted: 26-02-2022

Answer 4

If the web service can give you just a specified number of results(something like: requestData between index 1 and 10 or give me first 25 results) try to use that (put a simple "Load more results" button or implement an auto-loading mechanism). If the web service not provide this feature then try to save your xml on sdcard and when you need the data try to parse just a specified number of results. Hope this help!

Answered by: Briony577 | Posted: 26-02-2022

Answer 5

Why don't you use database? See Android Data Storage Guide

Answered by: Catherine283 | Posted: 26-02-2022

Similar questions

Recommendations for Android programming resources

android - Recommendations for a 'permanent' Selector in ListView

I'm looking for suggestions on how to go about adding a ListView selector that is 'permanent'. By this, I mean a single row in the ListView is always highlighted; it should move up or down in reponse to any D-pad presses (i.e. like the default selector) but also remain set/highlighted if the user were to scroll the ListView in either direction (i.e. it's still highlighted even when i...

android - Development Tablet Recommendations

After moving from Verizon to Sprint and buying several Android phones (EVO 4G), I became interested in developing Android applications. I have some programming experience (35+ years with various software firms (e.g. Cray Research, IBM, Oracle)) and would like to finally do some programming for myself. I'm looking for recommendations on Android tablets. After looking at the marketplace, I realized it really is "bu...

ios - Recommendations for .NET Web Service Format/Protocol for Android, iPhone, etc. integration

I am building a web service for my ASP.NET MVC 3 website. Ideally I would like all clients (my web pages, iphone application, android application, windows phone 7 application, etc.) to use the same service layer to load and save data. I am new to mobile development and was wondering if there is a preferred mechanism - SOAP/JSON/etc - to use a heterogeneous mobile device setup. Specifically I'm wondering if Android ...

android - Image sizes recommendations

I'm writing an application that shows a lot of images (currently using Gallery, but going to move away from that soon). Each image takes up the whole screen, with exception of an ActionBar at the top. My app will end up having about 80 images per gallery. I would like to provide appropriately sized images for different types of device, from small handsets to larger tablets. I know that I can use the ldpi, mdpi an...

Android: Recommendations for background image sizes for different screen densities?

Which is the correct sizes of background images for the different densities ldpi, mdpi, hdpi, xhdpi, xxhdpi? I have transparent background images (.png) and want to reduce image size as much as possible. (not concerning the .apk size, but concerning memory issues on lesser powerful devices) I assume, the first thing is to make sure the images are in the correct sizes, so that they do not need to be scaled. ...

What are the official Android recommendations for tabs?

I have to say I'm pretty lost when it comes to designing tabbed layouts on Android right now. The platform developers seem to be evolving the design faster than I can figure out their intentions. From what I can gather from the combination of the recently deprecated TabActivity and the new

Are there any recommendations for request codes values in Android?

Now I am using random numbers for request codes. So, every time I add new activity for startActivityForResult I need to check all other such activities to avoid collisions. May be there are any practices for defining values, non-collidable by design? What do you think?

android - Are Google Play billing security recommendations only for piracy prevention?

The instructions for Google Play's billing service (in-app purchases) mention a number of things you should do to hide your app's public key and create a complicated "payload" string unique to each user and each of their purchases for security reasons. My question may be ignorant, but I know absolutely nothing about hacking and what is possible. When they say "secure", are they only referring to security fr...

Need recommendations for overlay views or layouts in Android

In an Android app I have a background image and two buttons on it. This is a partial screenshot: I ask you for the best approach to click on the sinopsis button to show an overlay text, like this: and also to click the fotos button ...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android