Nested DialogFragment quit after rotation

I have a nested (!) Fragment that shows my PhotoNoteDialogFragment:

private void newPhotoNote() { mPhotoDialog = PhotoNoteDialogFragment.newInstance(this); mPhotoDialog.show(getFragmentManager(), PhotoNoteDialogFragment.TAG); } 

A dialog box appears, but it is discarded as soon as I rotate the device. I have already studied and tried these things several times without success:

  • set PhotoNoteDialogFragment # setRetainInstance (true). It does not work because nested fragments cannot be saved.

  • Use this piece of code in PhotoNoteDialogFragment to prevent an error that causes an unwanted call to quit the system:

  @Override
     public void onDestroyView () {
         if (getDialog ()! = null)
             getDialog (). setDismissMessage (null);
         super.onDestroyView ();
     }
  • Try calling show (), the method in my nested fragment # onActivityCreated, if the instance of the PhotoNoteDialogFragment is not null:
  @Override
   public void onActivityCreated (final Bundle savedInstanceState) {
     super.onActivityCreated (savedInstanceState);
     if (mPhotoNoteDialogFragment! = null) {
       mPhotoNoteDialogFragment.show (getFragmentManager (), PhotoNoteDialogFragment.TAG);
     }
   }

None of these attempts can cause DialogFragment to reappear after turning the screen. Does anyone else have an idea that I could try next ..? I have no ideas.

THX

+6
source share
1 answer

I think you do not need to redefine onActivityCreated , your dialogue is fine without it. I also tried. If you show the dialog on onActivityCreated , your application will onActivityCreated .

0
source

Source: https://habr.com/ru/post/947643/


All Articles