hey guys, I know it sounds stupid but why don’t I...
# android
o
hey guys, I know it sounds stupid but why don’t I get ANR? I am blocking the main thread for 10 seconds. I also tried Thread.sleep(10000)
🤔 1
h
ANR usually occurs when the app doesn’t respond to User interaction for more than n seconds. here you are blocking the main thread but probably not trying to intact with the app button click, view tap, scroll, swipe etc
o
I tried what you suggested with the following code, but it still doesn’t crash:
a
Try actual interactions aka click on the screen
p
delay()
does not block the thread. It pretty much schedule a Job to be executed at the specified time.
👆 2
It suspend the coroutine, whatever code block inside the runBlocking lambda, but it does not touch the underlaying thread.
r
But
runBlocking
should block the thread no ? 🤔
k
run blocking uses an event loop based dispatcher
i would still expect Thread.sleep to block the main thread, however
r
The dispatcher used for the coroutine block shouldn’t change that runBlocking is supposed to block the thread until the block completion. Or am I missing something ?
k
it does block. an event loop also blocks the main thread.
runBlocking
blocks in the same way. it continues to process events on the event loop until the work is completed.