My code have some sqlite operators. I execute a sql, it has 500 rows. Executing and getting rows take quite low time, but when I call cursor.close() function, it takes 10 seconds.
How can I reduce this time consume ?
Cursor cursor = database.rawQuery(sql, null);
while(cursor.moveToNext()){
String str1 = cursor.getString(0);
String str2 = cursor.getString(1);
System.out.println(str1+" and "+str2);
}
cursor.close(); // this line takes 13 seconds. but above code takes only 200 ms
code is something like this
I have suggest you to use method
startManagingCursor(Cursor c)of Activity Class. Lets Activity handle Cursor for you as per Activity Life Cycle..Form Docs StartManagingCursor…
This method is deprecated.
Use the new CursorLoader class with LoaderManager instead; this is also available on older platforms through the Android compatibility package.
This method allows the activity to take care of managing the given Cursor’s lifecycle for you based on the activity’s lifecycle. That is, when the activity is stopped it will automatically call deactivate() on the given Cursor, and when it is later restarted it will call requery() for you. When the activity is destroyed, all managed Cursors will be closed automatically.
If you are targeting HONEYCOMB or later, consider instead using
LoaderManagerinstead, available viagetLoaderManager().