0

I tried this code And Logged. But I thought I can see title text = 0 and then sleep 1 second and see text 1 and sleep and so on... But that was not. When I run this code, I just see text=3 after 4 second sleep. How to understand this? sleep method just stop UI process And don't stop background process?

        for (i in 0..3) {
            Log.d("TAG"," i : "+i)
            binding.title.text = "current="+i
            SystemClock.sleep(1000)
            //Thread.sleep(1000)
        }
user9628944
  • 131
  • 7
  • 2
    If you `sleep` the main thread, the UI will surely hang. – RamblinRose Apr 07 '20 at 02:10
  • 1
    Does this answer your question? [Sleep function in android program](https://stackoverflow.com/questions/8369718/sleep-function-in-android-program) – RamblinRose Apr 07 '20 at 02:10
  • I understand only that onCreate has UI Thread. The reason of what I misunderstand is that there is more theads at onCreate including ui thread? – user9628944 Apr 07 '20 at 02:30
  • there's only one thread on app start. You the programmer are in control of any additional threads. – RamblinRose Apr 07 '20 at 02:38

0 Answers0