Is It A Bug That Calling Methods That Update Android Ui From Another Thread Works?
I will give you two pieces of code. One code updates the UI for the child thread. Yes, you heard me correctly!
Solution 1:
This is not a bug, but it's not guaranteed to work, either. The Android UI toolkit API contract is that updates to the UI must be done on the UI thread (which is almost always the same as the main thread). What happens if you violate this rule by making an update from another thread, as you've done with your call to setText
, is not defined. It may work, it may have no effect, it may crash immediately, or it may subtly break things and/or crash later.
Many methods that are commonly mistakenly called from the wrong thread explicitly check what thread they're on, and crash if it's not the UI thread. This is a feature intended to help developers more easily catch their mistakes, rather than a required behavior of any UI-modifying method call.
Post a Comment for "Is It A Bug That Calling Methods That Update Android Ui From Another Thread Works?"