I can't seem to figure this one out. I'm new to android and I'm trying to show a dialog while querying a database from my website. The code functions properly aside from the fact that the ProgressDialog doesn't show until doInBackground() is complete which shouldn't be the case.

Here is the code

```
private class MyAsyncTask extends AsyncTask<Void, Void, Void> {

    private ProgressDialog mProgressDialog;
    private Context context;
    private String taskResult;

    public MyAsyncTask(Activity activity) {
        context = activity;
        mProgressDialog = new ProgressDialog(context);
    }

    @Override
    protected void onPreExecute() {
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setMessage("Performing Query...");
        mProgressDialog.show();
        Log.d("log_tag", "Showed dialog");
    }

    @Override
    protected void onPostExecute(Void result) {
        if (!error) {
            Log.d("log_tag", "No ERROR - " + error);
            JSONArray jArray;
            List<Map<String, String>> lValues = new ArrayList<Map<String, String>>();
            try{
                jArray = new JSONArray(taskResult);
                JSONObject json_data=null;
                //Log.d("log_tag", "for loop to read data");
                for(int i=0;i<jArray.length();i++){
                    json_data = jArray.getJSONObject(i);
                    Map<String, String> datum = new HashMap<String, String>(2);
                    datum.put("artist", json_data.getString("artist"));
                    datum.put("title", json_data.getString("title"));
                    lValues.add(datum);
                }
            } catch(JSONException e1){
                Message("No Results Found");
            } catch (ParseException e1) {
                e1.printStackTrace();
            }
            lstResults.setAdapter(new SimpleAdapter(context, lValues, 
                        android.R.layout.simple_expandable_list_item_2,
                        new String[] {"artist", "title"}, 
                        new int[] {android.R.id.text1, android.R.id.text2}));
        } else {
            Message("ERROR: " + errString);
            error = false;
            errString = "";
        }

        if (mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
            Log.d("log_tag", "Closed dialog");
        }

    }

    @Override
    protected Void doInBackground(Void... params) {
        StringBuilder sb;
        InputStream is = null;
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("c_name", generateSearchCriteria()));
        Log.d("log_tag", nameValuePairs.get(0).toString());
        try{
            Log.d("log_tag", "Create Object");
             HttpClient httpclient = new DefaultHttpClient();
             HttpPost httppost = new HttpPost(RHINOGOLD_URL);
             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
             HttpResponse response = httpclient.execute(httppost);
             HttpEntity entity = response.getEntity();
             is = entity.getContent();
        }catch(Exception e){
            errString = "Connection Error";
            error = true;
            Log.e("log_tag", "Error in http connection - " + error + " - " + e.toString());
        }

        //convert response to string
        if (!error) {
            Log.d("log_tag", "BufferedReader - " + error);
            try{
                  BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                   sb = new StringBuilder();
                   Log.d("log_tag", "append");
                   sb.append(reader.readLine() + "\n");

                   String line="0";
                   while ((line = reader.readLine()) != null) {
                                  sb.append(line + "\n");
                   }
                   Log.d("log_tag", "close input stream");
                   is.close();
                   if (sb.toString() == null) {
                       taskResult = "No values returned";
                   } else {
                       taskResult=sb.toString();
                   }
            } catch(Exception e) {
                errString = "The application encountered an error";
                error = true;
                Log.e("log_tag", "Error converting result - " + error + " - " + e.toString());
            }
        }
        return null;
    }
}

```

I'm sure there are a slew of programming no nos in here but as I said, I'm new so I'm still figuring out how all of this works. Anyway, as you can see I have some logs in here and I watch the LogCat output to see when the dialog pops up and here is what I get.

```
Showed dialog
c_name=artist LIKE 'journey' OR title LIKE 'journey'
Create Object
... (long pause)
BufferedReader - false
append
close input stream
No ERROR - false
Closed dialog

```

I don't see the dialog until after the ... (long pause) and it only shows for a split second. The lines after the pause happen so fast I'm not sure where exactly the dialog starts showing but from what I understand it should be showing before the long pause, specifically since I see the log "Showed dialog"

Can someone please help me figure out why my dialog shows up at the last minute?