Android在子线程里使用Toast报错Can't toast on a thread that has not called Looper.prepare()
生活随笔
收集整理的這篇文章主要介紹了
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();
總結
以上是生活随笔為你收集整理的Android在子线程里使用Toast报错Can't toast on a thread that has not called Looper.prepare()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++:30 ---C++类成员,成员函
- 下一篇: Android studio安装过程中入