异常处理 Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:php ruby perl python 编辑:程序博客网 时间:2024/06/05 12:48
Looper.getMainLooper()
如果你不带参数的实例化:Handler handler = new Handler();那么这个会默认用当前线程的looper
一般而言,如果你的Handler是要来刷新操作UI的,那么就需要在主线程下跑。
情况:
1.要刷新UI,handler要用到主线程的looper。那么在主线程 Handler handler = new Handler();,如果在其他线程,也要满足这个功能的话,要Handler handler = new Handler(Looper.getMainLooper());
2.不用刷新ui,只是处理消息。 当前线程如果是主线程的话,Handler handler = new Handler();不是主线程的话,Looper.prepare(); Handler handler = new Handler();Looper.loop();或者Handler handler = new Handler(Looper.getMainLooper());
若是实例化的时候用Looper.getMainLooper()就表示放到主UI线程去处理。
如果不是的话,因为只有UI线程默认Loop.prepare();Loop.loop();过,其他线程需要手动调用这两个,否则会报错。
参考:http://blog.csdn.net/thanklife/article/details/17006865
0 0
- 异常处理 Can't create handler inside thread that has not called Looper.prepare()
- Handler机制和Can't create handler inside thread that has not called Looper.prepare()异常
- Can't create handler inside thread that has not called Looper.prepare() 异常
- 异常Can't create handler inside thread that has not called Looper.prepare() 解决方法
- 解决异常Can't create handler inside thread that has not called Looper.prepare()方法
- Android中的Can't create handler inside thread that has not called Looper.prepare()异常
- Android : Can't create handler inside thread that has not called Looper.prepare() 异常
- 异常:Can't create handler inside thread that has not called Looper.prepare()
- android异常收集-Can't create handler inside thread that has not called Looper.prepare()
- studio 异常Can't create handler inside thread that has not called Looper.prepare()
- 异常:Can't create handler inside thread that has not called Looper.prepare()解决办法
- 解决Can't create handler inside thread that has not called Looper.prepare() inside AsyncTask
- Handler——Can't create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()错误的解决
- Can't create handler inside thread that has not called Looper.prepare()
- Can’t create handler inside thread that has not called Looper.prepare()
- Can’t create handler inside thread that has not called Looper.prepare()
- Can't create handler inside thread that has not called Looper.prepare()解决办法
- Objective-C继承
- 成绩排名
- 多线程 -- yield()方法和sleep()方法的区别
- 【学习笔记】JavaScript编码规范-类型
- 成绩管理系统
- 异常处理 Can't create handler inside thread that has not called Looper.prepare()
- SharePoint 2016 的新特性概览(一)(What's New for IT Professionals in SharePoint Server 2016)
- Android自定义View--验证码控件
- 陈怡暖:非农前或窄幅震荡走势
- Markdown 语法(0)- 序言
- C++中数字与字符串之间的转换
- 15年5月份笔记之刚接触开发板接口接线工具
- python对cookie的操作模块-cookielib
- 新硬盘挂载目录后文件消失解决办法