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();
}
}
}
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() .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With