[杂谈]关于Handler.post与View.post的区别
2013-01-26 13:26
423 查看
Android的线程分UI线程与非UI线程两类。而Handler是非UI线程向UI线程传递消息的桥梁。
除了非常常用sendMessage之外,Handler也提供了post(Runnable...),postDelayed等
风骚犀利的方法,利于我们使用“闭包式编程”。
View作为UI的一部分,也无例外的提供了一个淫荡的View.post(Runnable)方法,让我们在
UI线程中doSomeThing。灵活使用View.post。神马Handler,Activity.runOnUIThread,
都可以一边站去。
相同
在与UI线程的通信上,Handler与View,其实最终都做了同样的事情。就是将消息传递在UI线程
的消息队列里,执行一些处理操作。
不同的是
View.post方法想在非UI线程有效工作。如该方法的注释所说,必须保证该View已经被添加至窗口。
This method can be invoked from outside of the UI thread only when this View is attached to a window.
另外给一个stackoverflow的例子:
http://stackoverflow.com/questions/4083787/runnable-is-posted-successfully-but-not-run
除了非常常用sendMessage之外,Handler也提供了post(Runnable...),postDelayed等
风骚犀利的方法,利于我们使用“闭包式编程”。
View作为UI的一部分,也无例外的提供了一个淫荡的View.post(Runnable)方法,让我们在
UI线程中doSomeThing。灵活使用View.post。神马Handler,Activity.runOnUIThread,
都可以一边站去。
相同
在与UI线程的通信上,Handler与View,其实最终都做了同样的事情。就是将消息传递在UI线程
的消息队列里,执行一些处理操作。
不同的是
View.post方法想在非UI线程有效工作。如该方法的注释所说,必须保证该View已经被添加至窗口。
This method can be invoked from outside of the UI thread only when this View is attached to a window.
另外给一个stackoverflow的例子:
http://stackoverflow.com/questions/4083787/runnable-is-posted-successfully-but-not-run
相关文章推荐
- 关于Handler.post与View.post的区别
- Handler.post与View.post的区别
- runOnUiThread 、Handler.post、View.post之间的区别
- android-View.post与Handler.post的区别
- POST数据提交,关于System.Web.HttpUtility.HtmlEncode与System.Web.HttpUtility.UrlEncode的区别
- GET 与 POST,Handler,JSON 解析,Tomcat,导入第三方包 SmartImageView
- 关于Form的method属性get和post是有区别滴
- 关于form表单中method里get和post的区别
- httppost 200、300、400、500 错误分析,HttpPost、HttpGet关于URL重定向区别
- android中view.post和handle.post的区别
- 关于View的invisible和Gone的区别
- 关于HttpHandler和HttpModule区别,作用
- Android中Handler的post和sendMessage的区别
- ios 关于UIAlertView与UIActionSheet的区别,以及在使用过程中注意事项
- 关于get与post传递参数容量大小限制区别以及curl函数与file_get_contents的区别(面试)
- 关于Android View.post(Runnable ) 的使用
- 关于post与get方法的区别
- 昨天刚看了Handler和HandlerThread这个东西,不明白为什么要用这么复杂的东西,而且Handler直接post的话好像还不是子线程运行。那我再开发的时候直接用Thread行不行?两个有什么区别?
- android多线程handler+runOnUithread+view.post+handler.post 2013-
- handler.post和handler.sendMessage的区别和联系