Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my android application skipping frames when Thread.sleep is called?

I'm writing an android application which needs to display some text for a a few thousandths of a second, then blank it again. What I have now is it displaying the text, then using Thread.sleep, then setting the text back to null. Instead, what happens is, when I press the button, the app hangs for the set amount of time, the text never appears, and the logcat says "Skipped xxx frames! The application may be doing too much work on its main thread." What is going on, and is there a better way of doing things?

like image 418
SaintWacko Avatar asked Apr 23 '26 13:04

SaintWacko


1 Answers

Try using a runnable.

private Handler mHandler = new Handler();

//code to make text appear...

    mHandler.postDelayed(makeTextDisapear , 3000); // Replace 3000 with the number of milliseconds you want the text to display.

    private Runnable makeTextDisapear = new Runnable() {
            public void run() {
                // code to make text dissapear

                }
            };
like image 113
Jason Hessley Avatar answered Apr 25 '26 03:04

Jason Hessley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!