Android AsyncTask blocks UI thread -


i have asynctask performing database operations. problem when execute asynctask on threadpoolexecutor ui thread getting blocked. here code:

private class addtoqueue extends asynctask<string, void, string> {         int qlength = 0;              protected string doinbackground(string... params) {             if (db == null) return null;             db.delete(dbhelper.queuetable, null, null);             contentvalues cv = new contentvalues();             (int = 0; < qlength; i++) {                 cv.put(dbhelper.index, i);                 cv.put(dbhelper.path, items.get(i).getpath());                 cv.put(dbhelper.title, items.get(i).gettitle());                 try {                     db.insert(dbhelper.queuetable, null, cv);                 } catch (exception e) {                     e.printstacktrace();                 }                 cv.clear();             }             return "executed";         }          @override         protected void onpostexecute(string result) { }          @override         protected void onpreexecute() {             qlength = list.getadapter().getcount();         }          @override         protected void onprogressupdate(void... values) { } 

ok solved it. replaced

 contentvalues cv = new contentvalues();  (int = 0; < c.getcount(); i++) {      c.movetoposition(i);      cv.put(dbhelper.index, i);      cv.put(dbhelper.path, c.getstring(0));      cv.put(dbhelper.title, c.getstring(1));      try {          // db.insert(dbhelper.queuetable, null, cv);      } catch (exception e) {          e.printstacktrace();      }      cv.clear(); 

with one

 string sql = "insert " + dbhelper.queuetable + "(" +                       dbhelper.index + ", " + dbhelper.path + ", " +                       dbhelper.title + ") values (?, ?, ?)";  db.begintransaction();  sqlitestatement stmt = db.compilestatement(sql);  (int = 0; < c.getcount(); i++) {      c.movetoposition(i);      stmt.bindstring(1, + "");      stmt.bindstring(2, c.getstring(0));      stmt.bindstring(3, c.getstring(1));      stmt.execute();      stmt.clearbindings();  }  db.settransactionsuccessful();  db.endtransaction(); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -