N Czar N Czar - 5 months ago 48
Java Question

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() {
public void run() {

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



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.