原文:Android handler 报错处理Can't create handler inside thread that has not called Looper.prepare()

问题: 写了一个sdk给其他人用,提供一个回调函数,函数使用了handler处理消息 在使用这个sdk提供的函数时,报错: 使用方式是在service中使用。在activity中使用正常。 问题解决: 在调用handler的方法前执行Looper.prepare 。Looper用于封装了android线程中的消息循环,默认情况下一个线程是不存在消息循环 message loop 的,需要调用Loo ...

2014-01-02 16:18 0 15998 推荐指数:

查看详情

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()。 搜索后 ...

Mon Jan 14 00:10:00 CST 2013 3 133790
Can't toast on a thread that has not called Looper.prepare()

Android开发中Can't toast on a thread that has not called Looper.prepare()问题 说一下问题出现场景:   在一个Android项目中,利用okhttp进行网络访问判断用户输入的账号密码,当用户密码输错时弹出 Toast 进行提示 ...

Tue Nov 26 01:04:00 CST 2019 0 419
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM