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.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...