Can't create handler inside thread that has not called Looper.prepare()
来源:互联网 发布:知乎2016年度100问 编辑:程序博客网 时间:2024/06/14 17:57
错误信息:在Android开发中,如果在一个Thread中启动了一个ProgressDialog用来提示正在连接(也就是防假死),然后在Handler中dismiss()这个ProgressDialog,程序就直接挂掉,异常信息是:Can’t create handler inside thread that has not called Looper.prepare()
原因分析:本人遇到的情况是在程序刚开始时候调用ProgressDialog提示正在连接(防假死调用),后边在连接成功后dismiss()这个ProgressDialog,如果有错误信息(比如连接失败呀什么的)则在线程中调用Toast提示,然后当程序运行到Toast的地方的时候程序就直接挂掉了
解决方法:在调用Toast(或者AlertDialog)的地方的前面加上Looper.prepare(),后边加上Looper.loop()即可解决问题;也就是说用Looper.prepare()和Looper.loop()把Toast前后包起来。
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()解决办法
- springmvc三种全局异常处理
- Unique Binary Search Trees II
- ExtJs Window 组件
- jni编译时出现:warning: format '%d' expects argument of type 'int', but argument 4 has
- [Android Pro] android 杀死进程的方法
- Can't create handler inside thread that has not called Looper.prepare()
- install python-pip
- 一说出口就被误解的离职原因,这样补救!
- 如何在 Git 里撤销(几乎)任何操作
- MVP好文章转载
- 做好一个人
- smack android集成问题记录
- Linux 上安装 rlwrap
- MySQL(十一)常用函数