androidandroid-asynctask

AsyncTask onPostExecute not being called


The project I'm working on is slightly more complicated but I made this simple test to try to track down what was wrong with my code. The progress dialog never dismisses. I had it at one point where they weren't returning null. '

public class SyncTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new mTask(this).execute();
    }

    public class mTask extends AsyncTask<Void, Void, Void> {

        Context mContext;

        ProgressDialog progressDialog;

        public mTask(Context aContext) {
            mContext = aContext;
        }

        @Override
        public void onPreExecute() {

            progressDialog = new ProgressDialog(mContext);
            progressDialog.setMessage("New...");
            progressDialog.show();
        }

        @Override
        public Void doInBackground(Void... params) {
            return null;
        }  

        public Void onPostExecute(Void... params) {
            progressDialog.dismiss();
            return null;


        }
    }

}

Solution

  • The parameters are wrong, use this:

        @Override
        protected void onPostExecute(Void result) {
            progressDialog.dismiss();
            return;
    
        }