I’m quite new at android and SQL. I’m making an app, which can get data form the accelerometer, and the I’m storing them in a SQLLite database. Afterwards I intend to get the database out so I can plot the data. I have two questions:
-
How can I save the data as a usable file on the SD-card? I’ve seen some topics, but I couldn’t get any off it to work. I think I need some examples/tutorials.
-
Secondly, after some collection, the app starts to lag. I guess it is the storing method, which is like this in the DB-class:
public long createEntry(float x, float y, float z, float t) { ContentValues cv = new ContentValues(); cv.put(X_DATA,x); cv.put(Y_DATA,y); cv.put(Z_DATA,z); cv.put(TIME_DATA,t); return ourDatabase.insert(DATABASE_TABLE, null, cv); }
I hope you’ll help me.
For the first part of your question, performing all the inserts in a transaction should make it a lot faster. To do this, before you start inserting, call the following code:
Then once you’ve finished inserting data, call:
To answer the second part of question, you need to retrieve the data from the database and create a CSV file from it:
If you’re collecting a lot of rows (tens of thousands perhaps), you might need to stream this CSV out to the disk at the same time as writing it.