Why is it that invalidate () cannot be called directly in the thread

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.