2

I would like dismiss a DialogFragment on orientation change.

The problem is that the OnConfigurationChanged() is never called.

And call :

this.dismiss();

from the OnDetach() method, returns a null pointer exception. What could I do?

Greelings
  • 4,964
  • 7
  • 34
  • 70

2 Answers2

5

Overriding :

public void onPause() {
    super.onPause();

    this.dismiss();
}

instead of OnConfigurationChanged(), did the trick.

Greelings
  • 4,964
  • 7
  • 34
  • 70
  • Note that this also causes the DialogFragment to be dismissed whenever it goes into pause state for any reason, such as for example another Activity coming into the foreground. – Trevor Oct 07 '17 at 19:50
0

onConfigurationChanged not getting called

Add this to your manifest

android:configChanges="orientation|screenSize"
Community
  • 1
  • 1
Terry W
  • 203
  • 3
  • 9
  • I added it, but OnConfigurationChanged() is still not called. I think it is because it is a Fragment, not an Activity. – Greelings Mar 20 '16 at 19:21
  • Yes, I already saw this link. My problem is specific to the DialogFragment class. – Greelings Mar 20 '16 at 19:29
  • 1
    perhaps you could tie into the onConfigurationChanged() method of the activity that opens the dialog. When you show the Dialog you set a TAG, you can use this tag to find the dialog and dismiss it from the calling activity – Terry W Mar 20 '16 at 19:52