2011-02-14 39 views
1

親愛的 我有一個機器人活動,其中包含一個「的onChange」功能正常的.java類(當我的Skype聯繫人的屬性改變函數被調用)與Android溝通活動在正常的Java類

當我嘗試在我的onChange函數中調用alertdialog.show()時,出現錯誤「無法在未調用Looper.prepare()的線程中創建處理程序」,應如何在我的活動中顯示消息?在此先感謝

回答

1
class LooperThread extends Thread { 
     public Handler mHandler; 

     public void run() { 
      Looper.prepare(); 

      mHandler = new Handler() { 
       public void handleMessage(Message msg) { 
        // process incoming messages here 
       } 
      }; 

      Looper.loop(); 
     } 
    } 

From the android documentation

線程默認情況下不具有與其相關聯的消息循環;創建一個,備調用()的線程是運行循環,然後循環()把它處理消息,直到循環停止

也永遠不會有UI的(工人稱)線程。它必然會拋出異常。