2011-08-25 65 views
4

我有一個AsyncTask使用輪詢隊列來查看是否有新對象到達。當它檢測到新對象時,我將它作爲一個字符串收集信息,然後publishProgress(info)。在onProgressUpdate中,它將字符串添加到列表中。我遇到的問題是程序從不進入進度更新。我在調試器中通過它,我看到它調用publishProgress,但它永遠不會進入onProgress更新。看起來像這樣:publishProgress not calling onProgressUpdate

@Override 
    protected void onProgressUpdate(String... values) { 
     messageQueue.add(displayName + " : " + values[0]); //I have a breakpoint here that the program never hits. 
     ((BaseAdapter) getListAdapter()).notifyDataSetChanged(); 
     super.onProgressUpdate(values); 
    } 

    @Override 
    protected Void doInBackground(Void... params) { 
     while (true) { 
      Packet p = pc.pollResult(); 
      if(p != null){ 
       String body = ((Message) p).getBody(); //I have a breakpoint here that the program hits only when a new object is in the queue 
       publishProgress(body); 
      } 
     } 

    } 
+0

奇怪,你有沒有嘗試將字符串正文改爲String數組? – Jack

+1

對不起,這太浪費了一篇文章,我想我的模擬器只是在跳過自己。我重新啓動日食,一切正常工作... –

+0

我打算推薦,但認爲它可能downvoted :) – Jack

回答

2

我有一個問題,它沒有被調用,但我只是注意到我把錯誤的類。這當然是它想成爲的AsyncTask塊內,但instaead我已經創造了它該塊的

0

這可以幫助某人真正的錯誤

公告中的AsyncTask的第二個參數是指進度

AsyncTask<Params, Progress, Result> 

確保您的數據類型相匹配。

AsyncTask<URL, String, Long>{ 

    protected Long doInBackground(URL... urls) { 
    return long; 
    } 

    protected void onProgressUpdate(String... values) {} 


    protected void onPostExecute(Long result) {} 

} 
相關問題