Search code examples
androidsqliteaccelerometersensors

Record accelerometer sensor readings to SQLite or flat file?


I'm writing an Android app to record and save high-rate accelerometer data (and later gyroscope data). The schema of my data will look like:

timestamp, x_accel, y_accel, z_accel

Should I save the data into SQLite or into a flat file (using FileWriter and BufferedWriter, as explained here)? Which one has the lowest latency or is more appropriate?

Eventually I need to import the data as a csv file into Excel to create graphs. So if I write to SQLite, I need to later write it out to csv.


Solution

  • Either will work obviously, but my personal (non-advocating or backed up by anything) rule of thumb is that if you can accomplish your task with a File, go for it. It's way easier to write and manage than database code, and you'll be able to format it for CSV on-the-fly with no conversion needed later. I say don't over-think it. BufferedWriter will take care of writing out in large chunks for you, so just keep the output stream open until you're done recording your data and you shouldn't have any latency problems. (don't forget to flush() and close() when you're done, a rule as appropriate in Java as it is in life).