问题
Possible Duplicate:
Android: Toast in a thread
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
Can't we raise a toast from a Non UI thread ?
回答1:
You can use runOnUiThread()
For example
this.runOnUiThread(show_toast);
and in show_toast
private Runnable show_toast = new Runnable()
{
public void run()
{
Toast.makeText(Autoamtion.this, "My Toast message", Toast.LENGTH_SHORT)
.show();
}
};
来源:https://stackoverflow.com/questions/13267239/toast-from-a-non-ui-thread