CruelIO CruelIO - 1 month ago 11
Android Question

onProgressUpdate not called

Why is

onProgressUpdate
not being called?

public class DoStuff extends AsyncTask<Integer, Integer, String> {
private MainActivity activity;

public DoStuff(MainActivity a){
activity = a;
}

protected String doInBackground(Integer... params) {
Integer loops = params[0];
for (int i = 0; i <= loops.intValue() ; i++) {

SystemClock.sleep(1000);
publishProgress(new Integer((i / loops) * 100));

}
return "Done: " + loops.intValue();
}

protected void onProgressUpdate(Integer progress)
{
activity.updateProgress("" + progress.intValue() + "%");
}

}

Answer

You are using wrong signature for onProgressUpdate

Change

protected void onProgressUpdate(Integer progress)
{
    activity.updateProgress(""+progress.intValue() +"%");
}

to

protected void onProgressUpdate(Integer... progress)
{
    activity.updateProgress(""+progress[0].intValue() +"%");
}
Comments