Today occasionally on the Internet to see this article http://hold-on.iteye.com/blog/991403
1, as we all know, in the development of Android, non-UI threads cannot manipulate controls in the UI thread, that is, the UI is not thread safe;
2, but when the setprogress (int count) method of the ProgressBar control is invoked in a worker thread (not a UI thread), the program runs and
There is no exception,
3, but when the call to SetBackground (int color) or setvisibility (int v), the program is running after the exception
4, the first and 3rd said, but the 2nd can not understand
Question: Who can define "manipulating the main thread UI in a worker thread", such as Setprogress on the operating UI? What is the principle of general determination.
In fact, this is a typical multi-threaded security problem, of course, in Android can not be listed outside. In most applications, we typically have a UI thread, the Android UI Looper thread, and a communication thread that is responsible for interacting with the server side.
So why is it possible to invoke ProgressBar in a non-UI thread? Because the ProgressBar control is a variable of a non-UI thread, it is all of a non-UI thread, there is no problem with multi-threaded shared data, and methods such as setbackground (int color) are invoked in a non-UI thread. It involves the problem of invoking variables such as the context of the UI thread, which can have thread-safety implications.
In fact, many of the basic principles of computer science are interlinked, nothing more than to transform an implementation of the point of view, the problem needs to think more.