there is sth wrong with my Application,I try to add three Fragments in another Fragment,then the Eclipse show this:
java.lang.IllegalStateException: Can't retain fragements that are nested in other fragments
this is my code in the childFragments
getChildFragmentManager().beginTransaction()
.add(R.id.shop_fragment_container, shopTopOneFragment)
.add(R.id.shop_fragment_container, shopTopTwoFragment)
.add(R.id.shop_fragment_container, shopTopThreeFragment)
.hide(shopTopTwoFragment).hide(shopTopThreeFragment)
.show(shopTopOneFragment).commit();
any help will be appreciated
To pass data between fragments in the same fragment manager, the listener should be added to the destination fragment with requestKey in order to receive the result produces from another fragment with the same key.
You can use multiple instances of the same fragment class within the same activity, in multiple activities, or even as a child of another fragment. With this in mind, you should only provide a fragment with the logic necessary to manage its own UI.
Since all fragments are destroyed if the activity is destroyed, a simple answer could be calling getActivity(). isDestroyed() returning true if the activity is destroyed, therefore the fragment is destroyed.
Can't retain fragements that are nested in other fragments
This is a limitation of nested Fragments
. I'm guessing one or more of your child Fragments
have setRetainInstance(true)
somewhere in their code. You need to remove that to prevent the error.
EDIT: On further reading it seems if the parent Fragment
is calling setRetainInstance(true)
then it will cause the same exception due to the fact that attempting to retain the parent instance also attempts to retain the child Fragments
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With