I have reviewed many examples on different pages and the vast majority teach to insert 1 record at a time. and this makes it correct.
But for my case I have an api that returns a large amount of data, and inserting 1 time for each record takes too long.
checking the log indicates that the memory is being cleaned, causing very long timeouts.
What is the best way to do these inserts of large amounts of data.?
code fraction
public static String iterarDatos(SoapObject result, Context m_context) {
String res = "";
int nroRegistros = 0;
ZEMTable zemTable = new ZEMTable(m_context);
try {
SoapObject szem = result;
nroRegistros = szem.getPropertyCount();
if (nroRegistros > 0) {
zemBE[] zems = WSManager.RetrievezemFromSoap(szem);
zemTable.open();
for (int i = 0; i < nroRegistros; i++) {
zemTable.create(zems[i]);
}
zemTable.close();
}
} catch (Exception ex) {
}
return res;
}
where the create is the following.
public long create(zemBE tzem){
Log.i(TAG, "Inserting record...");
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ID,zem.id);
initialValues.put(KEY_REF,zem.ref);
initialValues.put(KEY_DESCRIP,zem.descrip);
initialValues.put(KEY_IDALMACEN,zem.idalmacen);
return mDb.insert(DATABASE_TABLE, null, initialValues);
}
The solution was to use SQLiteStatement
I explain.
the following query does it very fast.
insert table1 (field1, field2) value ('1','1'),('2','2'),('3','3'),('4','4'),(' 5','5'),('6','6'),('7','7'),('8','8'),('9','9')
this way it makes the inserts consecutive.