Long story short:
I got a CSV file with something like 8.000 records (and 4 fields). I have to download it and after that process it and insert each record in a sqllite table.
So I do with it a transaction:
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
try
{
String line;
int i=0;
do {
line = buffreader.readLine();
i++;
if(i==1)
continue; //Header of the CSV
if(line != null)
{
String[] values = line.split(";");
if(values.length != 4 )
continue;
sql = String.format("INSERT INTO TABLE (FIELD_1, FIELD_2, FIELD_3, FIELD_4) VALUES (%s, %s, %s, %s)",
values[0],
values[1],
values[2],
values[3]);
db.execSQL(sql);
}
}
while (line != null);
db.setTransactionSuccessful();
}
catch (SQLiteException ex)
{
Log.d(TAG, "Well.. : " + ex.getMessage());
throw ex;
}
finally
{
db.endTransaction();
}
Everything works fine, it takes like 8-9 seconds on my cellphone and other cellphone. Sadly on the Android device where this app have to run ( a white label device with a dualcore processor ) it takes 6-7 MINUTES!!!
Of course my boss is not happy about it, he do agree that on "regular" cellphone with a quadcore process everything is faster but we have to make it working where on this dualcore and 6-7 minutes looks like a problem.. Any idea about how to solve it ?