欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 人文社科 > 生活经验 >内容正文

生活经验

Can't create handler inside thread Thread that has not called Looper.prepare()

发布时间:2023/11/27 生活经验 75 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Can't create handler inside thread Thread that has not called Looper.prepare() 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

今天在子线程里面写了一个Toast 运行程序直接崩溃了

看了下log 如下

最后忽然想到了子线程里面不能直接使用Toast

然后 就添加了 Looper.prepare(); 和 Looper.loop();  

例如:

 Looper.prepare();
 Toast.makeText(MainActivity.this, "11111", Toast.LENGTH_SHORT).show();
 Looper.loop();

这样运行好了

总结

以上是生活随笔为你收集整理的Can't create handler inside thread Thread that has not called Looper.prepare()的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。