在 Android 中,Toast 必須在主執行緒(UI 執行緒)上顯示。若在 AsyncTask 的背景執行緒中直接呼叫 Toast,會出現「Can't create handler inside thread that has not called Looper.prepare()」錯誤。
有些開發者嘗試在背景執行緒中加入 Looper.prepare() 與 Looper.loop(),卻可能導致「Only one Looper may be created per thread」錯誤。正確的做法是使用 Activity 的 runOnUiThread,或透過 Handler 將訊息發送到主執行緒,再由主執行緒顯示 Toast。