Android sleep() without blocking UI

前端 未结 4 1440
无人及你
无人及你 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条回答
  •  -上瘾入骨i
    2020-12-14 08:43

    You can define a Handle in your Activity and use Handle.postDelayed() from Activity's onCreate()so you receive a message on that handle in 3 seconds. Upon receving you can enable the button.

    You can do the same using AsyncTask where in doInBackground() you just sleep for 3 sec. Then in onPostExecute() you enable the button.

提交回复
热议问题