2011-03-28 59 views
0

我试图显示线程中的Toast。在Android中创建一个内部线程处理程序

Toast.makeText(activity.getApplicationContext(), "This is the Toast message", Toast.LENGTH_LONG).show(); 

但抛出异常

java.lang.RuntimeException:Can't create a handler inside thread that has not called Looper.prepare(). 

我该如何解决这个问题?我已将Looper.myLooper().prepare();放在Toast.makeText(....).show();之前

当我完成此操作后,它不会抛出异常但不显示任何Toast消息。

那么我该如何解决这个问题呢?

在此先感谢。

回答

0

您可以创建异步任务的onPostExecute你敬酒的短信..试试这个..

protected void onPostExecute(Void result) { 
    Toast.makeText(ActivityName.this,"Your Text", Toast.LENGTH_SHORT).show(); 
    if (this.dialog.isShowing()) { 
    this.dialog.dismiss(); 
    } 
} 
相关问题