1. Why invalidate () cannot be called directly in the thread?
2. How does it violate single thread?
3. Why is the Android UI not thread-safe?
4. Why do Android UI actions have to be performed in the UI thread?
1. Why invalidate () cannot be called directly in the thread?
For:
Android provides the Invalidate method for interface refresh, but invalidate cannot be called directly in the non-UI main thread because he is violating the single-threaded model: Android UI operations are not thread-safe, and these operations must be called in the UI thread. For example, calling invalidate in a non-UI thread can lead to thread insecurity, which means that the UI thread (or other non-UI threads) also refreshes the interface when the interface is refreshed in a non-UI thread, causing multiple interface refreshes to be unsynchronized, resulting in thread insecurity
2. How does it violate single thread?
A: When an Android program starts running, there is a main thread that is created. This thread is primarily responsible for the display, update, and control interaction of the UI interface, so it is also called the UI thread. Because only the UI thread updates the interface,
Android is a single threading model. When an Android program was created, a process presented a single-threaded model-that is, the main thread, an exception occurred in the invalidate () refresh interface on a non-main thread (UI thread), meaning that it was not allowed to update ui,android with other threads.
3. Why is the Android UI not thread-safe?
A: The Android UI provides invalidate () to update the interface, while the invalidate () method is thread insecure.
4. Why do Android UI actions have to be performed in the UI thread?
A: The main thread of the UI is to update the UI interface to update the interface to see the effect of running.
Furthermore, Android UI operations are not thread-safe and must be executed in the UI thread. If you modify the UI directly in a child thread, the exception is caused.
From:http://chenjinhua1595515.blog.163.com/blog/static/21583214720140834012400/
Why invalidate () cannot be called directly in the thread