android - How can i reduce time in fetching of data from SQLite cursor? -


i using following code data sqlite, got perfect data in cursor.
when iterating cursor, takes >10 seconds fetch 31 records cursor.
my query takes time 0.016150 second(s) execute.

how can reduce time <1 second ?

cursor cursor = dbhelper.getfollowedvaluesforcalendar();      if(cursor!=null && cursor.getcount()>0)     {         cursor.movetofirst();          int followeddateindex   = cursor.getcolumnindex(info.followed_date);         int followedcountindex  = cursor.getcolumnindex(info.followed_count);         int successvalueindex   = cursor.getcolumnindex(info.success_value);         int isenableindex       = cursor.getcolumnindex(info.is_enable);                 {                    info.previousfolloweddayslist.add(cursor.getstring(followeddateindex));              info.previousfollowedvalueslist.add(cursor.getint(followedcountindex));             info.successvalueslist.add(cursor.getint(successvalueindex));             info.isenablelist.add(cursor.getint(isenableindex));         }while(cursor.movetonext());     }     else     {         //system.out.println(" records between dates ==============>>>> 0");     }      if(cursor!=null)         cursor.close(); 

you should not call getcount() on cursor unnecessarily, because expensive call. read this.

instead, suggest alter code below:

cursor cursor = dbhelper.getfollowedvaluesforcalendar();  while(cursor != null && cursor.movetonext()) {     int followeddateindex   = cursor.getcolumnindex(info.followed_date);     int followedcountindex  = cursor.getcolumnindex(info.followed_count);     int successvalueindex   = cursor.getcolumnindex(info.success_value);     int isenableindex       = cursor.getcolumnindex(info.is_enable);      info.previousfolloweddayslist.add(cursor.getstring(followeddateindex));      info.previousfollowedvalueslist.add(cursor.getint(followedcountindex));     info.successvalueslist.add(cursor.getint(successvalueindex));     info.isenablelist.add(cursor.getint(isenableindex)); }  if(cursor!=null)     cursor.close(); 

moreover, if know indexes' of columns, may take cursor.getcolumnindex out while further optimization.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -