Anonymous
Anonymous

Reputation: 4900

Stop Dialog from showing after orientation changes

I have a custom Dialog class in which I instantiate the dialog like this

dg = new Dialog(con); 
dg.requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = dg.getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
dg.setContentView(R.layout.listview_dialog_layout); 

//set views etc..

dg.show();

When an orientation change occurs in the activity that the dialog is shown the activity data changes are lost but the dialog still stays open. I would like the dialog to be dismissed at orientation changes just like it happens with the default Dialog created through an AlertDialog.Builder. How can I do that?

I prefer a solution that is implemented in the custom Dialog class instead of going to every activity and type dialog.dismiss(); at activity pause or stop

Upvotes: 1

Views: 814

Answers (1)

kpninja12
kpninja12

Reputation: 549

See my answer here

This method lets you detect orientation changes for a dialog without a reference to an Activity. It requires a custom view within the dialog, though. If you can pass an instance of your custom dialog class to the custom view, you can call dialog.dismiss(); directly within the onConfigurationChanged() method of the custom view.

Upvotes: 1

Related Questions