'Some fragments are lost on rotation

In my FragmentActivity I use several fragments. when configuration changed(on rotation) system destroys and re-creates each fragment.
I try to use this re-created fragments

mFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_frame);

and put it to new layout

getSupportFragmentManager().beginTransaction()
    .replace(R.id.fragment_frame, mFragment )       
    .commit();

but meet with strange behavior: several fragments are lost. they are not displayed on the screen more. in their place is empty.
Although the logs show that fragments are re-creates fine, but further shows that the fragment is again destroyed, again created and destroyed again.

I build test project for show problem more clearly and without husk.
and that demonstrable results (not enough reputation to insert pictures)
Activity started picture
Activity rotated picture

A,B,C,D is a fragments
As you can see after configuration changed some fragments are lost (B,D)

tell me what I'm doing wrong

here's the code to help (Edit:push code to gitHub in order to make it easier to try)

https:// github.com/nailgilaziev/TestFragmentsRetain

p/s sorry about links

here log cat after I rotate device

MainActivity: onPause Activity
MainActivity: onStop Activity
MainActivity: onDestroy Activity
A: onDestroyview
A: onDestroy
B: onDestroyview
B: onDestroy
C: onDestroyview
C: onDestroy
D: onDestroyview
D: onDestroy
MainActivity: onCreate Activity
A: onCreate
B: onCreate
C: onCreate
D: onCreate
MainActivity: replaced
MainActivity: onStart Activity
A: onCreateView
B: onCreateView
C: onCreateView
D: onCreateView

<--before this point all fine and then strange behavior began
for the lost fragments(B,D) are performed unnecessary calls-->

B: onDestroyview
B: onDestroy
D: onDestroyview
D: onDestroy
D: onCreate
D: onCreateView
MainActivity: onResume Activity


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source