2011-03-28 95 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(); 
    } 
} 
相關問題