Overlapping DialogFragment, recreated in wrong order when orientation changes

436 views Asked by At

I'm using two overlapped DialogFragment (I know, maybe it is not a good design pattern), and I have problem on orientation changes.

enter image description here

When the orientation changes, the most external DialogFragment (the smallest) go behind the most internal.

The simplest solution for my application can be to dismiss the most external DialogFragment, but I'm not able to do it, since setRetainInstance(false) seems not working with DialogFragment.

The fragment are added dinamically, calling:

DialogFragment fragment = CreateEventFragment.newInstance(0);
fragment.show(getFragmentManager(), CreateEventFragment.FRAGMENT_TAG);
1

There are 1 answers

0
GVillani82 On BEST ANSWER

I solved the problem, overriding the onSaveInstanceState, in this way:

@Override
    public void onSaveInstanceState(Bundle outState) {
        if(outState==null)
            super.onSaveInstanceState(outState);
    }

Now, after orentation changes, the outmost DialogFragment is mainteined external, so they are recreated in the right order.