javaandroidasync-onprogressupdate

onProgressUpdate is not being called android


I have this GetAllUsers(); in onCreate and I have this

private void GetAllUsers() {
  (new LoadingUsers(this)).execute();
} 

Then I have this

private class LoadingUsers extends AsyncTask < Void, Integer, String > {
  String TAG = getClass().getSimpleName();
  AlertDialog.Builder builderSingle;
  ArrayAdapter < String > arrayAdapter;@
  SuppressWarnings("unused")
  Context mContext;

  public LoadingUsers(Context context) {
    super();

    mContext = context;

  }

  protected void onPreExecute() {
    //            prgDialog.show();
    //            builderSingle = new
    Log.d(TAG + " PreExceute", "On pre Exceute......");
  }

  protected String doInBackground(Void...arg0) {

    Log.d(TAG + " DoINBackGround", "On doInBackground...");
    return null;
  }

  protected void onProgressUpdate(Integer...a) {
    super.onProgressUpdate(a);
    Log.d(TAG + " onProgressUpdate", "You are in progress update ... " + a[0]);


  }

  protected void onPostExecute(String result) {
    //            prgDialog.hide();
    Log.d(TAG + " onPostExecute", "" + result);


    MainActivity.this.pd.dismiss();
  }
}

I wanted to put a builderSingle = new AlertDialog.Builder(MainActivity.this); inside the protected void onProgressUpdate(Integer... a) { which has a AsyncHttpClient client = new AsyncHttpClient(); but unfortunately the onProgressUpdate does not get called at all. I know this because the log does not show. All other log are showing except the onProgressUpdate I have also have

@
Override
protected void onDestroy() {
  super.onDestroy();
  Log.i(TAG, "On Destroy .....");
}

@
Override
protected void onPause() {
  super.onPause();
  Log.i(TAG, "On Pause .....");
}

@
Override
protected void onRestart() {
  super.onRestart();
  Log.i(TAG, "On Restart .....");
}

@
Override
protected void onResume() {
  super.onResume();
  Log.i(TAG, "On Resume .....");
}

@
Override
protected void onStart() {
  super.onStart();
  Log.i(TAG, "On Start .....");
}

@
Override
protected void onStop() {
  super.onStop();
  Log.i(TAG, "On Stop .....");
}

OnStart and OnResume are being log as well.

Why is onProgressUpdate not being called? How to call the onProgressUpdated correctly?

Update

onPostExecute is being called as well on the onProgressUpdate is not


Solution

  • onProgressUpdate is called on the main thread each time publishProgress is called from within doInBackground (on the background thread). This facility is provided for your convenience if you choose to use it. It's primarily useful if your task involves some kind of loop, in which case you can call publishProgress at each iteration. If your task simply invokes some other code, and all the processing happens somewhere you can't control, then the publishProgress/onProgressUpdate mechanism isn't going to be useful to you. In that case, you might decide to display an indeterminate progress bar before starting the task and then hide the indeterminate progress bar after it's completed.