可能重复: 安卓:吐司在一个线程
我打电话从工作线程创建一个辅助类功能,其中我想提出一个敬酒,但我得到以下异常
I am calling a helper class function from a worker thread, wherein I am trying to raise a toast but I am getting following exception
Android Can't create handler inside thread that has not called Looper.prepare
我们不能提高从非UI线程举杯?
Can't we raise a toast from a Non UI thread ?
您可以使用 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();
}
};