Search code examples
androidxmlaccelerometer

Append XML efficiently to a large frequently updated XML file in Android


I am developing an Android application which collects accelerometer data and then logs it into an XML file for further processing. Every time a new value is receive, this will have to be appended to this XML file. What do you suggest to use for frequently and efficiently append to a large XML file please?


Solution

  • I think it depends much on how frequently you actually want to update it.

    'Every time a new value is received' is pretty much just constantly, since the device is often constantly moving. In that case i'd guess you can best just keep up a constant StringBuilder, and append data to that constantly.

    If you want to update it a bit less often, every few minutes or so, it might be better though to save your data into a database or object and parse that to xml when needed. Might not be the best performance, but less error sensitive.

    I'd advise you to use JSON instead if you can, since it has less overhead and your file might get pretty big after a couple of minutes.