force screen output before a Thread.sleep
If I try to do a screen output (Toast or setContentView) before a Thread.sleep it will not be displayed until after the sleep (or all the sleeps in the thread). This means that if I do an output after the Thread.sleep it will overwrite the first output. If I so a fo开发者_开发知识库rceLayout on the View before calling the Thread.sleep it does no good. It appears that Android stores up all the output and displays them at the end of the program. If I run such code as straightforward Java apps on the PC it works as just fine as intended.
You should not do a sleep()
on the UI thread, because that will block your entire UI (as you noticed).
If you want something to happen after a certain amount of time, you can post a delayed message by creating a Handler
and using its postDelayed()
method.
Hand the job to a Handler. I hope you aren't doing Thread.sleep on the UI thread, because that will always cause the screen to freeze (and possibly your program to be terminated as unresponsive).
精彩评论