博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android中不能在子线程中更新View视图的原因
阅读量:4575 次
发布时间:2019-06-08

本文共 945 字,大约阅读时间需要 3 分钟。

这是一条规律,很多coder知道,但原因是什么呢?

如下:

When a process is created for your application, its main thread is dedicated to running a message queue that takes care of managing the top-level application objects (activities, broadcast receivers, etc) and any windows they create. You can create your own threads, and communicate back with the main application thread through a Handler. This is done by calling the same post or sendMessage methods as before, but from your new thread. The given Runnable or Message will then be scheduled in the Handler's message queue and processed when appropriate.

SDK API中Handler章节中的一段。

意思是:

当进程的主线程创建后,将启动一个MessageQueue,用来管理Top-level组件对象(activity,broadcastReceiver)和你创建的所有窗口[也就是包括更新View的操作],你可以创建子线程,并在子线程中用Handler来与main线程通信。通过在子线程中调用Handler的post或sendMessage方法来实现。你所传递的Runnable或Message将在主线程Handler的MessageQueue中参与调度,并且在适当的时候执行。

 

最近在深入研究Handler,不是那么简单,累。

如果说错了,欢迎拍砖!

转载于:https://www.cnblogs.com/carmanloneliness/p/3503899.html

你可能感兴趣的文章
UIView的动画之初步学习
查看>>
中小企业实施OA的意义
查看>>
es6 数组
查看>>
JS判断是否在微信浏览器打开
查看>>
javascript中typeof和instanceof的区别
查看>>
数据结构-数组1
查看>>
jquery之别踩白块游戏的实现
查看>>
转载Eclipse中Maven WEB工程tomcat项目添加调试
查看>>
caller和callee的解析与使用-型参与实参的访问
查看>>
[转]JavaScript线程运行机制
查看>>
日期时间处理函数收集
查看>>
HDOJ树形DP专题之Anniversary party
查看>>
设计师 商业
查看>>
算法(例子)
查看>>
python操作Memcache
查看>>
凶猛现金贷背后的欲望深渊:女子网上撸81只猫,欠下70万元债
查看>>
IOS之KVC机制(Object-C篇)
查看>>
CommonJS规范
查看>>
ES6系列一 let const
查看>>
JQuery常用方法一览
查看>>