I am using ProgressDialog to display a spinner while a Thread is running. When the thread is finished, the dialog is removed from the view and another Activity is pushed onto the stack. The problem is, the dialog is not disposed of. When I go back to the Activity (pop the stack) and return to the previous Activity, the same instance of the ProgressDialog is being called (when asked to show dialog).
Create the dialog:
protected Dialog onCreateDialog(int id) {
progDialog = new ProgressDialog(this);
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDialog.setMessage("Searching for ..." + txtPart.getText().toString());
// Start thread
progThread = new AcmXmlSearchHelper(handler, txtTitle.getText().toString(), txtPart.getText().toString(), txtSection.getText().toString(), this);
progThread.start();
return progDialog;
}
Show the dialog:
showDialog(getProgressId());
Dismiss the dialog:
dismissDialog(getProgressId());
The easy solution is to call a ProgressDialog (showDialog()) with a unique id. However, I don’t think this is good use of memory. I could have a number of Dialogs hanging around in memory. How do I make sure the object is disposed?
Thx
Creating a nested AsyncTask class would probably clear things up for you: