Monday, February 24, 2014

Some issues Android UI thread?


1, why invalidate () can not be called directly in the thread?
2, which is contrary to how single-threaded?
3, android ui why not thread safe?
4, android ui Why must perform operations in the UI thread?

Ask you prawn?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
android itself is a single-threaded model.
Reply:
3, android ui why not thread safe?

In the operating results of different UI thread is not the same.

However, there is a UI control column outside: progressBar is thread safe.
Reply:
1, why invalidate () can not be called directly in the thread?
Answer:
Android provides a way to achieve Invalidate interface refresh, but can not directly call Invalidate the main non-UI thread, because he is against the single-threaded model: Android UI is not thread-safe operations, and these operations must be called on the UI thread. For example: to call in a non-UI thread invalidate causes the thread unsafe, that it might be in a non-UI thread to refresh the interface, UI thread (or other non-UI thread) also refresh the interface, thus leading to multiple interfaces refresh The operation can not be synchronized, resulting in a thread safe
2, which is contrary to how single-threaded?
A: An Android application starts running, there is a main thread Main Thread is created. This thread is mainly responsible for displaying the UI interface, updates, and interactive controls, so called UI Thread. Since only the UI thread to update the interface so that
Android is a single-threaded model. An Android program was founded, a Process is presented in a single-threaded model - namely Main Thread, unusual in a non-main thread (UI thread) redeployment invalidate () to refresh the screen, that other thread update UI, android in is not allowed.
3, android ui why not thread safe?
A: android UI provides invalidate () to update the interface, and invalidate () method is thread safe.
4, android ui Why must perform operations in the UI thread?
A: UI main thread is updated UI interface, updated interface to see the effect runs.
Furthermore Android UI is not thread-safe operations and these operations must be executed in the UI thread. If you directly modify the UI thread in the child, it will cause an exception.

Reply:
reference to the third floor orietech reply:
1, why invalidate () can not be called directly in the thread?
Answer:
Android provides a way to achieve Invalidate interface refresh, but can not directly call Invalidate the main non-UI thread, because he is against the single-threaded model: Android UI is not thread-safe operations, and these operations must be called on the UI thread. For example: to call in a non-UI thread invalidate causes the thread unsafe, that it might be in a non-UI thread to refresh the interface, U ......


There are problems, you can blog guestbook. Will promptly help you http://blog.csdn.net/ORIETech

ORIETech
Reply:
Thank you! Revenue up!
Reply:
Yeah benefit. . .

No comments:

Post a Comment