Android開發之在子線程中使用Toast


在子線程中使用Toast的時候,出現Force close。

錯誤提示:Can't create handler inside thread that has not called Looper.prepare()

解決方法:

1 Looper.prepare();
2 Toast.makeText(ActivityTestActivity.this, "toast", 1).show();
3 Looper.loop();

原因:

子線程只是一個普通的線程,其ThreadLoacl中沒有設置過Looper,所以會拋出異常


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM