吐司

2012-11-07 222 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(); 
    } 
};