publishProgress没有调用onProgressUpdate

Vin*_*ith 5 android android-asynctask

我有一个AsyncTask,它使用轮询队列来查看是否有新对象到达.当它检测到新对象时,我将它作为字符串收集信息,然后发布进度(信息).在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);
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

小智 2

我遇到了一个问题,它没有被调用,但我只是注意到我把它放在了错误的类中。它当然应该位于 AsyncTask 块内,但相反我在该块之外创建了它