java - I need help starting one method right after another method finishes, not during it -


i making game , after clicks, ball moves across screen takes time. trying method after ball stops moving. tried sleep , didnt work. looked @ asynctask , don't understand it. can point me in right direction or tell me how use asynctask code, thanks. new helpful.

this first part main class has code actions in game. afterkick() method action want happen after kick() method finishes.

    final framelayout main = (framelayout) findviewbyid(r.id.main_view);     main.setbackground(this.getresources().getdrawable(r.drawable.field));     newball = new ball(this);     main.addview(newball);         main.setontouchlistener(new view.ontouchlistener() {             public boolean ontouch(view v, motionevent event) {                  float x = event.getx();                 float y = event.gety();                 system.out.println("x:" + x + " y" + y);                  if(kick == false && attempt<10)                 {                     setheight(y, newball);                     kick(x,y,newball,main);                 }                 afterkick();                 // todo auto-generated method stub                 return false;             }         }); 

once kick() method called goes class creates ball. ondraw method keeps repeating until ball no longer gets redrawn because of invalidate.

@override protected void ondraw(canvas canvas){     super.ondraw(canvas);     canvas.drawbitmap(scaled, left, top, null);     if(topmax>=top)     {         setdone(true);     }     else if(straight == true && top> topmax)     {         kickstraight();     }     else if(righty == true && top>topmax)     {         kickright();     }     else if(midright == true && top>topmax)     {         kickmidright();     }     else if(midleft == true && top>topmax)     {         kickmidleft();     }     else if(lefty == true && top>topmax)     {         kickleft();     }     invalidate(); } 

i cant figure out how after invalidate no longer restarts ondraw method. useful, thanks!

asynctasks have get method force program wait output asynctask before continuing on. have asynctask return value when completed , in calling thread assign value variable.

 asynctask task = new asynctask().execute(params);  object output = task.get(); 

however, using method block ui thread. safer (and better) alternative make use of asynctask's onpostexecute method. called after doinbackground method complete , run on main ui thread.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -