Reputation: 9605
Curious to know the reason behind not allowing updating UI elements from background thread in Android.
Will main thread does something more (probably interacting with framework) after updating the UI elements so that changes can be seen on the screen.?
Is it the same case with other GUI tool kits?
Upvotes: 1
Views: 283
Reputation: 17278
If all threads were permitted to update the GUI objects, they'd have to be designed for thread safety (since the GUI must track its underlying state), introducing locks or critical sections around member variables and other shared resources. This would
Concurrency is hard, and any framework designer has to compromise. Now the burden is on you to ensure things happen in the right thread. You should isolate worker and communications tasks from the UI anyway, so it doesn't really add all that much of an onus.
Upvotes: 3