publishProgress 未调用 onProgressUpdate
我有一个 AsyncTask,它使用轮询队列来查看新对象是否已到达。当它检测到新对象时,我让它以字符串形式收集信息,然后发布Progress(info)。在 onProgressUpdate 中,它将字符串添加到列表中。我遇到的问题是程序永远不会进入onProgressUpdate。我在调试器中单步执行它,我看到它调用了publishProgress,但是它从未进入onProgress更新。看起来像这样:
@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);
}
}
}
I have an AsyncTask that uses polls a queue to see if a new object has arrived. When it detects the new object, I have it collect information as a string and then publishProgress(info). In onProgressUpdate it adds the string to a list. The problem that I am encountering is that the program never enters onProgressUpdate. I stepped through it in the debugger and I see it call publishProgress, however it never enters onProgress update. looks something like this:
@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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了一个问题,它没有被调用,但我只是注意到我把它放在了错误的类中。它当然应该位于 AsyncTask 块内,但相反我在该块之外创建了它
I had an issue where it wasnt getting called but I just noticed I put the in the wrong class. It of course it suppose to be inside the AsyncTask block but instaead I had created it outside of that block
来自 http://developer.android.com/reference/android/os/AsyncTask。 html
线程规则
为了使此类正常工作,必须遵循一些线程规则:
From http://developer.android.com/reference/android/os/AsyncTask.html
Threading rules
There are a few threading rules that must be followed for this class to work properly:
这可能会对遇到真正错误的人有所帮助
请注意,AsyncTask 中的第二个参数指的是 Progress
确保您的数据类型匹配。
This may help someone with genuine error
Notice the second argument in AsyncTask refers to Progress
Make sure your datatype matches.