Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android/Java: onProgressUpdate() not being called?

I've read similar threads on here, even googled but no solution.

onProgressUpdate() is just not being called.

Here's the code:

public class DoHardWork extends AsyncTask {

    @Override
    protected Object doInBackground(Object... params) {


        publishProgress("Requesting XML data");
        this.requestData();

        publishProgress("Returning results");
        this.returnResults();

        return null;
    }



    protected void onProgressUpdate(String text) {
        super.onProgressUpdate(text);
        MainActivity.setLog(text);
    }
}

I tried setting a breakpoint in onProgressUpdate() and it's never called. It's like the code is just ignored.

Someone had a similar problem and it turned out to be just eclipse just messing with him but i tried restarting it with no success.

Any ideas?

like image 575
qwerty Avatar asked May 22 '12 17:05

qwerty


1 Answers

I think that you missed somethings on your code. Try with this one:

private class DoHardWork extends AsyncTask<Void, String, Long> {
    protected Long doInBackground(Void... urls) {
         publishProgress("Requesting XML data");
         this.requestData();

         publishProgress("Returning results");
         this.returnResults();

         return null;
    }

    protected void onProgressUpdate(String... progress) {
        super.onProgressUpdate(progress);
        MainActivity.setLog(progress[0]);
    }


}
like image 154
Pablo Avatar answered Sep 20 '22 18:09

Pablo