Take the 2-minute tour ×

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?

share|improve this question
> Is it the same case with other GUI tool kits? AFAIK, it is in all popular GUI toolkits. –  Sergey Glotov Oct 19 '10 at 13:03
add comment

1 Answer

up vote 3 down vote accepted

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

  • slow the GUI down
  • complicate the code,
  • not be 100% safe anyway.

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.

share|improve this answer
add comment

Your Answer


