我有一个 AsyncTask,用于轮询队列以查看是否有新对象到达。当它检测到新对象时,我让它将信息收集为字符串,然后发布进度(info)。在 onProgressUpdate 中,它将字符串添加到列表中。我遇到的问题是程序从未进入 onProgressUpdate。我在调试器中逐步执行代码,看到它调用了 publishProgress,但它永远不会进入 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);
}
}
}