[英]Android UI Thread Rendering Worker Thread
Android uses MessageQueue (pipeline thread pattern) to process UI events (such as button clicks, mouse movement, orientation changes, screen redraw and so on).
Android使用MessageQueue(管道线程模式)处理UI事件(例如按钮单击,鼠标移动,方向更改,屏幕重绘等)。 This allows you to change a button caption without having to worry that the user will click the button at the same moment.
这使您可以更改按钮标题,而不必担心用户会同时单击按钮。
But when we post Message to worker thread MessageQueue ( which is different with UI Thread MessageQueue )
但是,当我们将Message发布到工作线程MessageQueue时( 与UI Thread MessageQueue不同 )
How the Rendering happen? 渲染如何发生?
I mean to say we can perform rendering only on UI thread then how it is possible with worker thread too.
我的意思是说我们只能在UI线程上执行渲染,然后也可以通过工作线程执行渲染。
Please correct me if I am wrong... 如果我错了请纠正我...
As per my understanding. 根据我的理解。
We cannot directly update the UI from the worker thread. 我们无法从工作线程直接更新UI。 But, we can follow a series of steps as suggested in android document to update the contents of UI from a worker thread.
但是,我们可以按照android文档中建议的一系列步骤来从工作线程更新UI的内容。
Handler
object associated with main thread Handler
对象 Runnable
to the main thread from the worker thread at appropriate time. Runnable
发布到主线程。 This Runnable will be invoked on the main thread. 此Runnable将在主线程上调用。 This mechanism is implemented with
Looper and Handler classes.
该机制通过
Looper and Handler classes.
Please feel free to add to the answer. 请随时添加到答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.