Android在子线程里使用Toast报错Can't toast on a thread that has not called Looper.prepare()

在接android SDK的时候有时候为了方便debug调试查看,通过Toast输出相关信息,

实际上这个是在子线程中输出的,在logcat里查看有如下报错java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare()。

解决办法为先调用Looper.prepare();再调用Toast.makeText().show();最后再调用Looper.loop();

发布了141 篇原创文章 · 获赞 118 · 访问量 163万+

猜你喜欢

转载自blog.csdn.net/pbymw8iwm/article/details/102967694