简体   繁体   中英

Accessing Android UI toolkit from worker thread

According to Android doc, "...Additionally, the Andoid UI toolkit is not thread-safe. So, you must not manipulate your UI from a worker thread—you must do all manipulation to your user interface from the UI thread. Thus, there are simply two rules to Android's single thread model:

Do not block the UI thread Do not access the Android UI toolkit from outside the UI thread"

That seems very plausible, but is it correct that the compiler does NOT complain at all if a programmer violates the second rule?

Thank you.

You will not get a compile-time error. You may (or may not) get a run-time error.

Can you tell me the situation where you need to access UI toolkit from the thread ? There are many ways to update UI like

  1. Handler
  2. AsyncTask
  3. runOnUiThread method of View
  4. BroascastReceiver

I hope this help

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