2011-08-25 87 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) {} 

}