views:

47

answers:

3

Which is favourable, efficient and faster? storing information in xml format and retrieving it or storing information in a db on android?

and also, in terms of portability, xml could be stored as an asset...can the same be done with db? do db come in as default package in all phones.

application involves dealing with over 1000 records of data.

A: 

You can't use assets/raw folders as writable resources. They're readonly.

So basically you have 2 options:

  1. Store data to DB (SQLite)
  2. Store data in preferences - in fact XML file stored somewhere/smth like

    /data/data/[your package]/shared_prefs

My personal choice: if data size is more than 100 records - use DB, if less preferences.

barmaley
A: 

My choice is

  1. I use DB for structured data. When there is certain need in searching through data set by some fields or sorting by different fields. Use DB when there is additional logic is required.
  2. I use "shared prefferences" files when there is only need in persistence of data. No additional logic, only key value pairs.
ponkin
+1  A: 

A SQLite DB will be faster when it entails large amounts of data - it will find what you want much faster.

For small amounts of data a KML file will have a much smaller overhead than the DB, but isnt very useful for dynamic data.

If the data needs to be updated or added to, you would have to store the file in a writable location if you want to continue using the xml file.

For around 1000+ entries I would be looking to use a SQLite DB - you could do one of two things here - precompile a DB for your application, then place the DB file into the asset folder, then on first run check if the DB file exists - if not move the file from the asset forlder to the DB folder (see note below). Alternatively you could store the entries in a KML file in the asset folder, then on first run use a parser to write each entry from the kml file into a DB.

Getting files from the KML or a CSV file would take a while to process depending on the number of entries. I have an app which will get data from a csv file on the SDCard, and load it into a DB, as a test around 7,000 entries took about 35 seconds on a desire. Also I think the raw and asset folder has a size limit of around 1mb.

Take a look at this link, it shows a very useful way of moving a large DB on first run of the application:

Database Populating Solution

Scoobler
thank you so much Scoobler... this is of great help indeed... Scoobler.. I believe you have worked on developing apps that I am trying to develop now. Could you please tell me, how do I refresh the map (say every 10 seconds) on receiving the kml content from the webserver. I have the server which would generated the dynamic KML and send the info through the output stream
raqz
This really depends upon how you are processing the data as it comes in from the server. To get the map to refersh I use: mapView.postInvalidate(); (as it is running in a thread). You could possibly use a delayed handler http://stackoverflow.com/questions/1520887, but you would need to be loading you overlay every time before you invalitade the view so as its redrawn it shows the new overlay items. // Add the overlay to the map: map_overlays.add(po);
Scoobler
@Scoobler.. thanks a lot. I have been able to use handler and communicate the server every 10 seconds. I referred this example http://android-developers.blogspot.com/2007/11/stitch-in-time.html
raqz