Reputation: 2266
I know we should refresh UI in the main thread,and if we want to update UI in another thread we can use handler , blablabla...
but Why? Maybe it has some thing to do with resource competition?
Any help will be appreciated.
Upvotes: 3
Views: 179
Reputation: 8142
This is not only in android. In basically every gui framework the ui can be updated only from the ui thread. For more info Why must UI elements always be created/updated from the UI thread?
Upvotes: 7
Reputation: 73484
Because the Android UI toolkit is not thread-safe. So if you update the UI not on the UI thread you can experience weird problems that can be hard to track down and fix.
Upvotes: 1
Reputation: 17258
Efficiency and responsiveness. Otherwise, you'd get inconsistent data and crashes, alternatively, the whole UI would have to lock and unlock resources constantly. You really wouldn't like the speed of such a user interface on a resource constrained mobile device.
Upvotes: 5