DiveInto
DiveInto

Reputation: 2266

In android, why UI can not be updated out of UI thread?

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

Answers (3)

Mojo Risin
Mojo Risin

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

Robby Pond
Robby Pond

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

Pontus Gagge
Pontus Gagge

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

Related Questions