PublishProgress not calling onProgressUpdate

I have an AsyncTask that uses polls in a queue to see if a new object has appeared. When it discovers a new object, I collect the information as a string and then publishProgress (info). In onProgressUpdate, it adds a string to the list. The problem I am facing is that the program is never included in onProgressUpdate. I went through it in the debugger and I see that it calls publishProgress, however it never introduces the onProgress update. It 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);
            }
        }

    }
+5
source share
3 answers

, , , . , , AsyncTask, instaead

+2

http://developer.android.com/reference/android/os/AsyncTask.html

Threading

, :

execute(Params...) must be invoked on the UI thread.
+1

This may help someone with a genuine mistake.

Note that the second argument in AsyncTask is Progress

AsyncTask<Params, Progress, Result>

Make sure your data type matches.

AsyncTask<URL, String, Long>{

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

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


    protected void onPostExecute(Long result) {}

}
0
source

All Articles