Process dialog which is being displayed while some task is being performed in back ground doesn't gets cancelled after completion of task
<p>I'm displaying a process dialog when a task is being performed in background, the problem is, it's not being cancelled/dismissed after its work is done.</p>

<p>This is my AsyncTask class:</p>

<pre><code>public class FetchEmployeeAsyncTask extends AsyncTask&lt;String, Void, ArrayList&lt;Employee&gt; &gt;   {

private CaptureActivity activity;
private ProgressDialog progressDialog;
public FetchEmployeeAsyncTask(CaptureActivity nextActivity) {
    this.activity = nextActivity;
}

@Override
protected ArrayList&lt;Employee&gt; doInBackground(String... url) {
    // TODO Auto-generated methoVoidd stub
    ArrayList&lt;Employee&gt; employees = null;
    for(String employeeUrl : url){
        employees = fetch(employeeUrl);
    }
    return employees;
}

private ArrayList&lt;Employee&gt; fetch(String url) {
    // TODO Auto-generated method stub
    ArrayList&lt;Employee&gt; employees = null;
    String response = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);

        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
        response = EntityUtils.toString(httpEntity);
        employees = EmployeeXMLParser.employeeParser(response);
        System.out.println("Size in fetch "+employees.size());

        //System.out.println("Employee Name :: " + employees.get(0).getFirstName() + " " + employees.get(0).getLastName());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } /*catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        System.out.println("Error parsing the response :: " + response);
        e.printStackTrace();
    }*/
    return employees;
}

@Override
protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
    progressDialog = new ProgressDialog(activity);
    progressDialog.setCancelable(true);
    progressDialog.setTitle("Fetching Employees!!");
    progressDialog.setMessage("Please wait...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setProgress(0);
    progressDialog.show();
}

@Override
public void onPostExecute(ArrayList&lt;Employee&gt; employees){
    super.onPostExecute(employees);

    System.out.println("in post execxute "+employees.size());
    progressDialog.dismiss();
    activity.showEmployees(employees);


}
}
</code></pre>

<p>This class is being called from an activity class.
This is my Activity class:</p>

<pre><code>public class CaptureActivity extends Activity {

private String url = "";

FetchEmployeeAsyncTask employeeAsyncTask = new FetchEmployeeAsyncTask(this);
SelectedEmployeeAsyncTask selectedEmployeeAsyncTask = new SelectedEmployeeAsyncTask(this);
private ArrayList&lt;Employee&gt; employees = null;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    employeeAsyncTask.execute(new String[] {url});

    System.out.println("Status "+employeeAsyncTask.getStatus());

    setContentView(R.layout.activity_capture);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_capture, menu);
    return true;
}



public void showEmployees(ArrayList&lt;Employee&gt; employees) {
    // TODO Auto-generated method stub
    System.out.println("Status 2  "+employeeAsyncTask.getStatus());
    TableLayout employeeTable = (TableLayout) findViewById(R.id.main_table);

    TableRow header = new TableRow(this);
    header.setId(100);
    header.setBackgroundColor(Color.rgb(255, 165, 0));
    //header.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    TextView empCodeHeader = new TextView(this);
    empCodeHeader.setId(200);
    empCodeHeader.setText("Employee Code");
    empCodeHeader.setTextSize(16);
    empCodeHeader.setPadding(2,2,2,2);
    empCodeHeader.setWidth(200);
    header.addView(empCodeHeader);

    TextView empNameHeader = new TextView(this);
    empNameHeader.setId(201);
    empNameHeader.setText("Employee Name");
    empNameHeader.setTextSize(16);
    empNameHeader.setPadding(2,2,2,2);
    empNameHeader.setWidth(300);
    header.addView(empNameHeader);}
</code></pre>
