Android: What does posting a runnable from another thread onto the main thread actually do?

前端 未结 2 1218
-上瘾入骨i
-上瘾入骨i 2021-01-06 18:15

So, as the title says: What actually happens when you post a runnable from another thread onto the main thread?

I\'ve seen lots of questions asking how you do it, an

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-06 18:29

    There are bunch of other runnables that the MainThread executes, such as updating the UI, touch events. The 'time' is when the posted runnable is ready to be dequeued. If any other runnable came before it, your runnable will wait.

    There is no such thing here as interruption. Your button will submit burst of runnables, as same as submitting same number of runnables from many different threads.

    If you have a message that is non-short (whatever contains LONG word is bad for UI) operation will block the execution of other recurrent tasks submitted in the queue, most of often demonstrated with no updates (for task that execution is indeterminate) on the UI at all or junking if it is matter of burst of runnables that execution takes longer than 8ms.

提交回复
热议问题