I understand开发者_如何学编程 that Android applications have a single UI thread.
Does the runtime enforce that all UI calls are made from this thread, or is it up to the programmer to make sure no UI calls are made from other threads?
If you try to touch a view from another thread other than the owning UI thread you will get a nice CalledFromWrongThreadException.
JAL
You cannot operate on UI items when not on UI thread. For example, you cannot change the text of a textView from a non-UI thread. You are responsible to make sure you are on UI thread when working with UI items.
You need to do every operation with UI widgets in the UI thread. To do so you can use different approaches. I will list a few articles for you to read:
- Android's Handler
- Handling Expensive Operations in the UI Thread
- Painless Threading
精彩评论