简体   繁体   中英

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). 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 )

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.

Please correct me if I am wrong...

As per my understanding.

We cannot directly update the UI from the worker thread. But, we can follow a series of steps as suggested in android document to update the contents of UI from a worker thread.

  1. Create a Handler object associated with main thread
  2. Post a Runnable to the main thread from the worker thread at appropriate time.

This Runnable will be invoked on the main thread. This mechanism is implemented with Looper and Handler classes.

Please feel free to add to the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM