views:

42

answers:

1

Hey all,

I would like to know if it is possible to get 'leftover' calls to AsyncTask#onProgressUpdate after AsyncTask#onPostExecute has been called? I am setting text on the same TextView using both of them, and I don't want to set text such as "Done!" and then have it overwritten at a later point by text such as "Almost there - 90%"

Also, I am assuming that the onProgressUpdate method works similar to a SwingWorker method in that multiple calls to publishProgress may stack up before a call to onProgressUpdate occurs. I would really like to know where the "newer" and "older" progress updates are on the parameter - aka are the newest updates at position 0 in the parameter, or at position progress.length?

+1  A: 

The code to publishProgress is:

protected final void publishProgress(Progress... values) {
    sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
            new AsyncTaskResult<Progress>(this, values)).sendToTarget();
}

The sendToTarget call uses Handler#sendMessage which the docs say "pushes the message onto the end of the message queue." I understand that to mean that you will not get any out of order updates and that they will stack up. Also, for each publishProgress call there will be a corresponding onProgressUpdate call.

Qberticus
Interesting! Thanks for taking the time to look this up! Guess it doesn't work the same way as the SwingWorkers :)
Hamy