I occasionally see this on the internet todayArticleHttp://hold-on.iteye.com/blog/991403
1. We all know that in Android development, non-UI threads cannot operate controls in the UI thread, that is, the UI is non-thread-safe;
2. When the setprogress (INT count) method of the progressbar control is called in the working thread (non-UI thread,ProgramRun and
No exception,
3. If setbackground (INT color) or setvisibility (int v) is called, an exception occurs after the program runs.
4. Let's talk about the first and third points, but the second point cannot be understood.
Problem:Who can give a definition under "operate the main thread UI in the working thread", for example, is the preceding setprogress used to operate the UI? What is the general determination principle?
In fact, this is a typical multi-threaded security issue, of course, it cannot be excluded from Android. In most applications, we usually have a UI thread, that is, the android UI logoff thread, and a communication thread, responsible for interacting with the server.
So why can I call progressbar in a non-UI thread? The progressbar control is a variable of a non-UI thread. It is not owned by a non-UI thread and does not involve multi-thread data sharing. Instead, it calls methods such as setbackground (INT color) in a non-UI thread, it involves calling the context and other variables of the UI thread, so there is a thread security risk.
In fact, many basic principles in computer science are the same. They are nothing more than changing the implementation perspective. You need to think more about the problems you encounter!