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();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章