Android fragment orientation change

EDIT:

I have a DialogFragment where the link inside the parent Activity is NULL after changing the device orientation. How to fix it?

Creating a fragment:

 MyFragment myFragment = MyFragment.newInstance(title); myFragment.show(getFragmentManager(), tag); 

After changing orientation:

 MyFragment myFragment = (MyFragment)getFragmentManager().findFragmentByTag(tag); myFragment.dismiss(); //NULL pointer exception here 
+4
source share
1 answer

myFragment.setRetainInstance(true); for salvation.


Edit:

Also override onDestroyView in the Dialog dialog box:

 @Override public void onDestroyView() { if (getDialog() != null && getRetainInstance()) getDialog().setOnDismissListener(null); super.onDestroyView(); } 

This is the result of the following problem: http://code.google.com/p/android/issues/detail?id=17423

+3
source

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


All Articles