How to make asynctask work properly
<p>I have a button on my app, if the user click it, it will refresh the current page by calling onResume(), and there are lots of database operations in onResume(). Instead of keeping the button stay pressed for a while, I would like to use asynctask to make a progressdialog while loading the data. But the problem is that the button will still be in pressed state and the progressdialog only show at the end of the operation for a very short duration.</p>

<pre><code>RefreshButton.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {
                onResume();
            }
        });

protected void onResume()
    {
        doneloading = false;
        monResumeloading = new onResumeloading();
        monResumeloading.execute();
        ....loading...

            doneloading = true;
    }

private class onResumeloading extends AsyncTask&lt;Integer, Integer, String&gt;
    {
        private ProgressDialog progressDialog;
        @Override
        protected void onPostExecute(String result)
        {
            progressDialog.dismiss();
        }

        @Override
        protected void onPreExecute()
        {
            progressDialog = new ProgressDialog(StatisticsActivity.this);
            progressDialog.setMessage("Loading...");
            progressDialog.setCancelable(true);
            progressDialog.show();

            Log.i(TAG, "              doneloading=false");
        }

        @Override
        protected void onProgressUpdate(Integer... values)
        {

        }

        @Override
        protected String doInBackground(Integer... params)
        {
            while(!doneloading)
            {
                publishProgress(0);   //dummy
                            log.i(TAG, "loading");
            }
            return null;
        }


    }
</code></pre>

<p>I observed that the "loading" log is showing right after the asynctask execution and stop right after the boolean doneloading becomes false. But the progressdialog is not working properly. Please help me :(</p>
