1. 程式人生 > >執行緒呼叫Toast出現Can't create handler inside thread that has not calledLooper.prepare()問題

執行緒呼叫Toast出現Can't create handler inside thread that has not calledLooper.prepare()問題

解決方法出處https://blog.csdn.net/sunhuaqiang1/article/details/46839045

解決辦法:線上程中的Toast前後加上Looper.prepare()及Looper.loop()。

原因:建立新程序的情況下預設不會建立新的訊息佇列,而Toast需要先是在一個訊息佇列中,因此需要建立Looper的例項來繫結Handler進行訊息迴圈。