Android开发报错 Can't create handler inside thread that has not called Looper.prepare()

来源:互联网 发布:md5加密 js url 编辑:程序博客网 时间:2024/05/25 01:36
错误信息:在Android开发中,从主线程调用非主线程中的方法,程序就直接挂掉,异常信息是:Can't create handler inside thread that has not called Looper.prepare()

原因分析:在非主线程中调用Toast提示,然后当程序运行到Toast的地方的时候程序就直接挂掉了

解决方法:在调用Toast(或者AlertDialog)的地方的前面加上Looper.prepare(),后边加上Looper.loop()即可解决问题;也就是说用Looper.prepare()和Looper.loop()把Toast前后包起来

0 0