0

i have a dialog fragment when i rotate the device the dialogFragment is not appearing.
please look at the images to better understand

[![this is how the dialog looks][1]][1]

[![this is how i want to be][2]][2]

launching the dialog

ft = activity.supportFragmentManager.beginTransaction()
                //show the fragment
                userDialogFragment.show(ft, "user")
ismacil jama
  • 69
  • 1
  • 7

2 Answers2

1

i think u missed to invoke setRetainInstance(true). It controls whether a fragment instance is retained across Activity re-creation (such as from a configuration change). If set, the fragment lifecycle will be slightly different when an activity is recreated

Additional reference: https://stackoverflow.com/a/15444485/1992013

Birender Singh
  • 513
  • 6
  • 16
0

When I had experienced this problem it was because I had a check like

if(savedInstance == null{
      do...
}

in both my fragment and main activity. This was stopping my fragment from being reattached. So I removed the check in my fragment activity. I also manually controlled rotation through the code below (allowing me to support two fragments in landscape and one in portrait

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
        if (Orientation.equals("L")){return;}
        setContentView(R.layout.activity_land);
        Orientation = "L";
    }

    else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
        if (Orientation.equals("P")){return;}
        setContentView(R.layout.activity_main);
        Orientation = "P";
    }
}

Along with "android:configChanges="orientation". Though this may not be the solution to your problem, more code would be helpful.

ShadowRz
  • 11
  • 3