android – 为什么单线程模型用于将UI更新为主线程?

前端之家收集整理的这篇文章主要介绍了android – 为什么单线程模型用于将UI更新为主线程?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Qt doc说,

As mentioned,each program has one thread when it is started. This
thread is called the “main thread” (also known as the “GUI thread” in
Qt applications). The Qt GUI must run in this thread.

Android文档说,

Like activities and the other components,services run in the main
thread of the application process

而iOS,

It is strongly recommended not to update UI controls etc from a
background thread (e.g. a timer,comms etc). This can be the cause of
crashes which are sometimes very hard to identify. Instead use these
to force code to be executed on the UI thread (which is always the
“main” thread).

为什么他们使用单线程模型来更新UI?

解决方法

简单的答案是,确保显示没有损坏是唯一合理的方法.

最长的答案是允许多个线程更新UI会导致死锁,竞争条件和各种麻烦.这是Java AWT(其他UI系统)教授的令人痛苦的教训,允许多个线程触摸UI.参见,例如,this blog post.

原文链接:https://www.f2er.com/android/312806.html

猜你在找的Android相关文章