Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the onProgressUpdate() of AsyncTask<> interface is never called?

Tags:

android

The onProgressUpdate() is never called, can you tell me why?

private class LoginMe extends AsyncTask<Context, Void, Boolean> {

    @Override
    protected Boolean doInBackground(Context... arg0) {
        doSomething();
        return true;
    }

    @Override
    protected void onProgressUpdate(Void... v) {
        super.onProgressUpdate(v);
        Log.d("Dev", "Im in onProgressUpdate()");
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        if (result) {
            doOne();
        } else {
            doTwo();
        }
    }
}
like image 254
Eugene Avatar asked Mar 07 '11 19:03

Eugene


People also ask

How do I use onProgressUpdate in AsyncTask?

onProgressUpdate() is used to operate progress of asynchronous operations via this method. Note the param with datatype Integer . This corresponds to the second parameter in the class definition. This callback can be triggered from within the body of the doInBackground() method by calling publishProgress() .

How do you implement AsyncTask?

To start an AsyncTask the following snippet must be present in the MainActivity class : MyTask myTask = new MyTask(); myTask. execute(); In the above snippet we've used a sample classname that extends AsyncTask and execute method is used to start the background thread.


1 Answers

You have to call publishProgress from within doInBackground manually.

doInBackground(Params...), invoked on the background thread immediately after onPreExecute() finishes executing. ... This step can also use publishProgress(Progress...) to publish one or more units of progress. These values are published on the UI thread, in the onProgressUpdate(Progress...) step.

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

like image 152
Leo Avatar answered Sep 28 '22 08:09

Leo