Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:手机主板检测软件 编辑:程序博客网 时间:2024/04/30 12:00
因为Toast在创建的时候会依赖于一个Handler,并且一个Handler是需要有一个Looper才能够创建,而普通的线程是不会自动去创建一个Looper对象,比如说在某个Activity中能new一个Handler是因为Android系统在启动一个Activity的时候会默认的创建一个Looper对象,因此不能够在子线程中显示Toast,你可以在开启的子线程中执行Looper.prepare()来构建一个Looper,然后在显示Toast,但是不要忘记执行Looper.loop()来加载这个Looper,当然,也可以使用主线程的Looper,获取主线程的Looper的方法是Looper.getMainLooper();同时需要注意的是,同样的不能在子线程中去更新UI界面,因为Toast是相对独立于UI界面的,就好比应用虽然crash掉了,并且已经返回到home界面,但是Toast依然会在hone界面显示出来。
(摘自:百度知道网友)
0 0
- 解决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()
- 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()
- 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()
- 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()解决办法
- SparkR安装部署及数据分析实例
- Object类源码学习
- 快速幂模板
- 百度的冬天:曾梦想成伟大公司 却为何陷入危机
- Struts2访问Servlet API的3种方式
- Can't create handler inside thread that has not called Looper.prepare()
- 自定义ToolBar
- IOS OPENGL ES 之EAGLContext上下文配置
- (七) spring_Bean的作用域
- acm之贪心算法题目6
- 理解postgresql数据表与其对应的数据文件关系
- UISwitch
- 欢迎使用CSDN-markdown编辑器
- [bzoj2733][HNOI2012]永无乡