Is there any faster way to iterate through rows from Sqlite query?

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.

  • Android Parcelable and Serializable
  • InflateException: Couldn't resolve menu item onClick handler
  • Dialog size does not match the background image
  • Android NestedScrollView has wrong size after app:layout_behavior
  • 'android-24' requires JDK 1.8 or later to compile
  • Programmatically add view one below other in relative layout
  • Is there any faster way for looping on rows in android and Sqlite?

    Thanks,

  • Google Cloud Messaging - GCM - SERVICE_NOT_AVAILABLE
  • How to use MapView in android using google map V2?
  • how to highlight the selected Item of Recycler View?
  • Gson - Same field name, different types
  • How to stop the Timer in android?
  • Unable to resolve imports from external dependencies in Android Studio 2.0 Preview 5 + Preview 6
  • One Solution collect form web for “Is there any faster way to iterate through rows from Sqlite query?”

    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 getColumnIndex calls on every iteration, you will be loosing precious time. Do it once, store the value.

    Use traceView to 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

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.