title: Why won't Fragment retain state when screen is rotated?
body: <p>I've been having some trouble getting some custom DialogPreference subclasses inside a PreferenceFragment to remain visible when the screen is rotated. I don't experience this problem when using a PreferenceActivity, so I don't know whether it's an Android bug or a problem with my code, but I'd like someone to confirm whether they are having the same experience.</p>
  
  <p>To test this, first create a preference screen containing at least one DialogPreference (it doesn't matter which subclass). Then display it in a PreferenceActivity. When you run your app, press on the DialogPreference so that it's dialog shows. Then rotate the screen so the orientation changes. Does the dialog remain visible?</p>
  
  <p>Then try the same, but with a PreferenceFragment to display your preferences instead of a PreferenceActivity. Again, does the dialog remain visible when you rotate the screen?</p>
  
  <p>So far, I've found that the dialog will remain visible if using a PreferenceActivity, but not if using a PreferenceFragment. Looking at the <a href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/preference/DialogPreference.java">source code for DialogPreference</a>, it seems that the correct behaviour is for the dialog to remain visible, because <code>isDialogShowing</code> is the state information that gets saved when <code>onSaveInstanceState()</code> is called on screen re-orientation. Therefore, I think a bug may be preventing the PreferenceFragment (and everything inside it) from restoring that state information.</p>
  
  <p>If it is an Android bug, then it has far-reaching implications, because anyone using PreferenceFragment cannot save and restore state information.</p>
  
  <p>Can someone please confirm? If it's not a bug, then what is going on?</p>