Android sleep() without blocking UI

前端 未结 4 1441
无人及你
无人及你 2020-12-14 07:44

For my new Android application I need a function, that timeout my application for 3 Seconds. I tried the function \"sleep()\" like this:

seekBar1.setProgress         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 08:25

    You shouldn't ever block the ui thread with a sleep. Its ok to sleep on another thread, but even then it should be avoided. The right way to do this is to post a Runnable to a Handler. Then put whatever code you want to run after the delay in the run() method of the Runnable.

提交回复
热议问题