java - Android Thread.sleep() in AsyncTask freeze UI -


i'm tried many suggestions nothing works! when call thread.sleep() in background thread, main thread freezes time (animation frame drop) :(

version 1:

public void updatechannels(final arraylist<channel> channels) {     new asynctask<arraylist<channel>, object[], void>()     {         @override         protected void doinbackground(arraylist<channel>... arraylists)         {             for(channel channel : arraylists[0])             {                 integer chid = new integer(channel.arfcn);                 channelrect channelrect = channels.get(chid);                 publishprogress(new object[] {channelrect, channel.dbm});                  try                 {                     thread.sleep(1000);                 } catch (interruptedexception e)                 {                     e.printstacktrace();                 }             }             return null;         }          @override         protected void onprogressupdate(object[]... values)         {             channelrect channelrect = (channelrect) values[0][0];             int value = (integer)values[0][1];             channelrect.setvalue(value);             channelrect.animate();         }     }.execute(channels); } 

version 2:

 public void updatechannels(final arraylist<channel> channels) {     new thread(new runnable()     {         @override         public void run()         {             for(final channel channel : channels)             {                 int chid = new integer(channel.arfcn);                 final channelrect channelrect = channels.get(chid);                 if(channelrect != null)                 {                     currentactivity.runonuithread(new runnable()                     {                         @override                         public void run()                         {                             channelrect.setvalue(channel.dbm);                             channelrect.animate();                         }                     });                     try                     {                         thread.sleep(500);                     } catch (interruptedexception e)                     {                         e.printstacktrace();                     }                 }             }         }     }).start(); } 

and tried same thing post , handler. same thing :( when thread.sleep(500) arrives animation freezes :(

what i'm doing wrong?

update 1

found heavy place slows ui thread:

i have horizontal linearlayout stores 175 channelrect views. when call animate (that starts alphaanimation okay, when setvalue() channelrect must change size:

public void setvalue(int value) {     _value = value;     setopacity((byte)255);     currentlayoutparams.height = (int)((-110 - value) * ycoeff * -1);     requestlayout(); } 

this slow downs main ui thread. why? setvalue affects 1 view in linearlayout not all... p.s. removing requestlayot() line remove slowdowns channelrect size not changes :(

the reason why animation freezes it's requestlayout() in channelrect. main linearlayout contains many (175+) custom views trying redraw every children on requestlayout() called updated child.

i'm changed channelrect drawing rectangle inside view , calling invalidate() instead requestlayout():

public void setvalue(int value) {     _value = value;     setopacity((byte)255);     invalidate(); }  @override protected void ondraw(canvas canvas) {     canvas.drawrect(0,getheight() - (int)((-110 - _value) * ycoeff * -1),size,getheight(), pnt); } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -