android async tasks -


i have application getting data particular day response web-server , plotting o/p graph depending on data(number/time) has come.

right invoking web-server async task.

i can fling across multiple screens(previous day/next day) invoke web-server multiple times(multiple async tasks) data server.

the issue when number of flings(async tasks) increasing application shows anr.

is there better way handle these kind of scenarios rather creating async task each , every web-server call(fling).

adding portion of code:

if(e1.getx() - e2.getx() > swipe_min_distance            && math.abs(velocityx) > swipe_threshold_velocity) {       valuesdaywithtime=onstart(dateprevious); }    public graphview onstart(string date){     urlfinal=createurl();     new downloaddatatask(this).execute(urlfinal); }  private class downloaddatatask extends asynctask<string, integer, long> {      yieldactivity yactivity;     progressbar pbar ;     downloaddatatask(yieldactivity act){         yactivity=act;     }      protected void onpreexecute() {         rellay=(relativelayout) findviewbyid(r.id.graphview);         pbar         = new progressbar(yactivity);         layoutparams lp =new layoutparams(layoutparams.fill_parent,layoutparams.fill_parent);         pbar.setlayoutparams(lp);         pbar.setmax(100);         rellay.removeallviews();         rellay.addview(pbar);     }      protected long doinbackground(string... urls) {         int totalcount = urls.length;         (int = 0; < totalcount; i++) {             publishprogress((int) ((i / (float) totalcount) * 100));             downloadfromurl(urls[i]);         }         return (long) totalcount;     }      protected void onprogressupdate(integer... progress) {         log.i(progress[0] +"%");     }      protected void onpostexecute(long result) {          graphviewday=calculate(datenow,valuesdaywithtime);         rellay.removeview(pbar);         rellay.addview(graphviewday);       } }  public void downloadfromurl(string fromurl) {     try {         gethttpresponse(fromurl.tostring());          parseresponse();         }      } catch (ioexception e) {         e.printstacktrace();     } catch (xmlpullparserexception e) {         e.printstacktrace();     } } 

as long creating asynctask objects on main thread , calling execute on them main thread, there shouldn't problem. can post pseudo code asynctask ? can find more on asynctask here.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -