views:

555

answers:

3

This seems to be an Android-wide problem, which you can see in API demos under Views -> Progress Bar -> Dialogs.

Basically, if you show a progress dialog, it works as expected the first time around. If you dismiss it and show it again (without destroying the activity or anything like that), the spinning image stops spinning. In the API Demo you can see this by clicking "Show Indeterminate", pressing back to dismiss the dialog, and clicking the button again.

I've tried constructing my own progress dialog, however it shows the same problem, as the problem is with the "ProgressBar" spinning image.

I am wondering if anyone has a workaround for this problem.

+2  A: 

Hi,

If you dismiss a Dialog, you must not show the same instance again. Either create a new one, or use hide() instead of dismiss(). When using hide() you still have to dismiss() it when no longer needed.

ognian
+3  A: 

You don't have to use onCreateDialog for ProgressDialog objects, as explained here http://developer.android.com/guide/topics/ui/dialogs.html#ProgressDialog . You should create and show the progress dialog in the main code instead of using showDialog and onCreateDialog.

cristis
A: 

You can declare a ProgressDialog instance in your Activity and override onCreateDialog(int). Then instead of making a call to showDialog(int) you just assign your instance of ProgressDialog the call to onCreateDialog(int) where you will call dialog.show().

public class Home extends Activity {

ProgressDialog recordingDialog;

//where you want to call the dialog
recordingDialog = (ProgressDialog)onCreateDialog(RECORDING_DIALOG_KEY);


@Override
protected Dialog onCreateDialog(int id) {
    ProgressDialog dialog = new ProgressDialog(this);

    switch (id) {
    case RECORDING_DIALOG_KEY:
        ((ProgressDialog) dialog).setIndeterminate(true);
        dialog.setCancelable(false);
        ((ProgressDialog) dialog)
                .setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setMessage("Recording...");
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Stop",
                dialogStopListener);

        dialog.show();

        break;
    default:
        dialog = null;
    }
    return dialog;
}
}
moose