吐司

2012-11-07 219 views
1

可能重複:
Android: Toast in a thread吐司

我打電話從工作線程創建一個輔助類功能,其中我想提出一個烤麪包,但我我得到以下異常

Android Can't create handler inside thread that has not called Looper.prepare 

我們不能從非UI線程提出一個敬酒嗎?

+0

不,你不能.. – Guna

+1

爲什麼你沒有張貼此問題之前,使用谷歌? –

+0

你不能那樣做。抱歉。 您必須調用UI線程才能顯示Toast –

回答

8

您可以使用runOnUiThread()例如

this.runOnUiThread(show_toast);

show_toast

private Runnable show_toast = new Runnable() 
{ 
    public void run() 
    { 
     Toast.makeText(Autoamtion.this, "My Toast message", Toast.LENGTH_SHORT) 
        .show(); 
    } 
};