I am using the following lines for looping on rows of a Sqlite query.
this.open(); // opening db
Cursor cursor = db.rawQuery(strQuery, null);
cursor.moveToFirst();
do {
// do something
} while (cursor.moveToNext());
cursor.close();
When the number of rows is about 15000 it takes long time. It takes about 4 seconds for empty while block and about 6 second for while block that has some codes. It shows that iterating on rows in this way is time consuming.
Is there any faster way for looping on rows in android and Sqlite?
Thanks,
Optimizing what you do inside the loop is the only way of improving the speed of the whole operation. For instance if you’re doing
getColumnIndexcalls on every iteration, you will be loosing precious time. Do it once, store the value.Use
traceViewto locate where you’re loosing time and improve it there. Sadly I can’t give a concrete answer, since I don’t know what you’re doing inside the loop.Traceview Debugging