微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/android/312806.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐