tags:

views:

73

answers:

1

Hi,

I'm facing some problems with the progress dialogs. I use a managed progress dialog to show the user that an operation is being carried out with the following code written in the onCreateDialog(int id) function:

          case PROGRESS_DIALOG :
            {
                dialog = new ProgressDialog(this);                                      
                dialog.setMessage(getResources().getString(R.string.eStrUpdating));
                dialog.setCancelable(true);
                dialog.setOnCancelListener(new DialogInterface.OnCancelListener()
                {
                    public void onCancel(DialogInterface dialogInterface)
                    {
                       Log.i(TAG,"progress dialog cancelled ");
                    }
                });
                return dialog;
            }

When the operation completes I call dismissDialog(PROGRESS_DIALOG). The problem is that if I rotate the phone while the progress dialog is displayed then when the operation completes the dismiss call has no effect and the progress remains showing. And this I cannot understand why.

A: 

When you rotate the phone, the Activity is destroy and recreated. Then you should call dismiss on your dialog, in the onDestroy method of your activity and recreate it.

Sephy
Well the thing is that the dialog is managed by the activity , and the activity should handle things like dismissing it when the activity is destroyed and showing it when it is created/resumed.
I think the dismiss has no effect because when you rotate, as I said, a new instance of Activity is created, so I suppose a new dialog too. so maybe you are trying to do the dismiss on the previous dialog?
Sephy