Showing the progress dialog during searching google map with AsyncTask
<p>I would like to display a progress dialog when server is looking for the address on the google map, when the progress is finished, the dialog disappears. I googled it and the most of result is talking about AsyncTask, however I am still confused about the parameter of the function doInBackground() and the usage of onPreExecute() and onPostExecute(). Could someone give me some solutions about that. I really appreciate with any help, thanks.</p>

<pre><code>protected void mapCurrentAddress() {
    String addressString = addressText.getText().toString();
    Geocoder g = new Geocoder(this);
    List&lt;Address&gt; addresses;
    try {
        addresses = g.getFromLocationName(addressString, 1);
        if (addresses.size() &gt; 0) {
            address = addresses.get(0);
            List&lt;Overlay&gt; mapOverlays = mapView.getOverlays();
            AddressOverlay addressOverlay = new AddressOverlay(address);
            mapOverlays.add(addressOverlay);
            mapView.invalidate();
            final MapController mapController = mapView.getController();
            mapController.animateTo(addressOverlay.getGeopoint(), new Runnable() {
                public void run() {
                    mapController.setZoom(12);
                }
            });
            useLocationButton.setEnabled(true);
        } else {
            // show the user a note that we failed to get an address
            alert(this, addressString);
        }
    } catch (IOException e) {
        // show the user a note that we failed to get an address
        e.printStackTrace();
    }
}

private class SearchAddress extends AsyncTask&lt;Void, Void, Void&gt; {
        private final ProgressDialog dialog = new ProgressDialog(AddLocationMapActivity.this);

      // can use UI thread here
      @Override
      protected void onPreExecute() {
          this.dialog.setTitle("Checking");
          this.dialog.setMessage("Contacting Map Server...");
          this.dialog.show();
      }

      // automatically done on worker thread (separate from UI thread)
      @Override
      protected Void doInBackground(Void... params) {
          try {

              mapCurrentAddress(); 
          }
          catch(Exception e) {
              Log.e("DEBUGTAG", "Remote Image Exception", e);
          }
          return null;
      }

      // can use UI thread here
      @Override
      protected void onPostExecute(Void res) {
          if (this.dialog.isShowing()) {
              this.dialog.dismiss();
          }
      }

      @Override
      protected void onProgressUpdate(Void... values) {
          // TODO Auto-generated method stub
          super.onProgressUpdate(values);
      }

}
// this is the click event
mapLocationButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new SearchAddress().execute(); // crash during doing the doInBackground
            //mapCurrentAddress(); // work perfectly
        }
    });
</code></pre>

<p>The application crashes after popup the progress dialog ?</p>
