Nik
Nik

Reputation: 472

Progressdialog fails to get dismissed because of Activity recreate

I have a dialog box which syas Loading during Activity create and a dialog.dismiss later down in the code inside a runnable. Now at a certain point in Activity onCreate my Activity is recreated to get information about requested permissions. The problem is the dialog.dismiss is not getting triggered in the runnable. The dialog box is never getting dismissed.

 dialog = ProgressDialog.show(TripActivity.this, "", "Loading...");

final Handler handler1 = new Handler();

                handler1.post(new Runnable() {
                    @Override
                    public void run() {

                   //     b=oldvalue;
                     //   mListener.doYourWork(id_share);
                        // Post again 16ms later.
                        handler1.postDelayed(this, 5000);


                        dialog.dismiss();

Upvotes: 1

Views: 68

Answers (1)

BMacedo
BMacedo

Reputation: 778

Everytime you call onCreate the line ProgressDialog.show() returns a new ProgressDialog reference.

You should check if dialog is null before trying to create it again. Also, remember to dismiss it when the activity calls onDestroy.

Upvotes: 2

Related Questions