3

I need to store my android app content and want tips on what storage i should use. SQLite database or XML file(s)?

Some characteristics of the app and the data:

  1. The application is used for tracking (daily) the body measurements of weight, waist, chest, ++
  2. The measurement types are divided in separately tabs and are not dependent on/related to each other
  3. Entities contains small amount of data, 4-5 attributes
  4. The amount of data is expected to be moderate. Maximum (30 measurement in the months x 5 measurement types = 150 measurements in months/1800 in the year)
  5. None advanced queries are going to be used. Mainly reading (all data elements) and adding new measurements.
  6. I want to enable easy sharing/exporting of the measurement data to for instance dropbox or email.

I guess that there are none performance issues storing the data in XML-file with these requirements/characteristics. If so, should I separate each measurement type in separately XML-file and where on the mobile device should I store the files?

Ismar Slomic
  • 5,315
  • 6
  • 44
  • 63

3 Answers3

5

I would read over the Storage Options you have available on Android to try to dig up some more information.

What you described, one time writing to files that are in drop box seems like writing out to an XML file that is saved in your dropbox seems like a good choice. No complexed queries, just read in one record at a time.

However, I feel it wouldn't be that much more work to go with a SQL database. And this would be way more flexible in the long run. Right now you don't want to do queries, but you may some day. Plus you won't have to worry about splitting your data into several files and parsing things. Parsing can quickly become bothersome when you try scaling.

What I would recommend is to write a ContentProvider and then put all your details in there. That way your program won't care about how the data is stored in case you want to change it later because the Provider does all heavy lifting for you. I would much rather use a CursorAdapter than anything else, and your get from using SQLite. Plus all the new CursorLoader keep up the performance of you application.

Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
  • Thanks for the useful thoughts. I think you are right, in the long term it is probably right decision using the database as a storage. The import/export of data in XML format is one time action and is easy to solve. – Ismar Slomic Aug 05 '12 at 17:00
  • Well another thing to think about is that you are going to have to write an AsyncAdapter to upload your database to the cloud as opposed to letting dropbox do it. Either way I would still opt for a ContentProvider so you can hide all the nasty details. – Frank Sposaro Aug 05 '12 at 18:50
3

The best long-term solution would be to use an SQLite database.

But if you wish to use XML, a great solution is already presented here: Store static data in Android - custom resource?

Community
  • 1
  • 1
bunbun
  • 2,595
  • 3
  • 34
  • 52
0

If your XML data is large. XML parsing and then insert is a very expensive operation and is time-consuming.

Some issues which you will face with XML parsing and insert.

a. XML parsing is memory intensive and so you heap size will grow, you need to keep an eye on this as this might cause crash. b. Inserts in SQLite DB will take around ~100ms per tuple (row), so you can calculate the time it will required to pump in thousands of rows of data.

If you data is not too large don't bother about using SQLite.

Furqi
  • 2,403
  • 1
  • 26
  • 32