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 + Data Binding @style
  • Troubles installing programmatically an app with INSTALL_PACKAGES permission from /system/app
  • How to broadcast referral to android app intallation
  • 'Open Declaration' in Eclipse navigates to class files instead of to source files for Android Libraries
  • Varying windowSoftInputMode for fragments inside the viewpager
  • MultiDexApplication not recognized
  • Is there any faster way for looping on rows in android and Sqlite?

    Thanks,

    Related posts:

    Android naming convention
    Remove action bar shadow programmatically
    EditText afterTextChanged not working
    Floating Action Button expansion
    Text view with different colored texts in xml code
    Add transition to an AnimationDrawable
  • java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared: findLibrary returned null (tess-two)
  • Firebase FCM force onTokenRefresh() to be called
  • Android how to sort JSONArray of JSONObjects
  • Android, Scala and Proguard
  • Gradle 2.3.0-alpha1 doesn't work data binding
  • Replace Retrolambda with Android Studio 3.0 Java 8 built-in features
  • 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.