Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android support 3 or more levels of nested fragments?

I'm having many crashing issues when programmatically adding 3 levels of nested fragments. Currently, I have an Activity which loads Fragment A through its fragmentManager, which then loads Fragment B through A's childFragmentManager, which then loads Fragment C from B's childFragmentManager.

The fragments initially load up fine. But the problem is when the fragments are destroyed and then re-created. You'd think that when Fragment B gets destroyed, so will Fragment C. But it seems like Fragment C is left dangling.

As it is now, Fragment B gets loaded through a ViewPager in Fragment A. As I swipe from page to page, I occasionally get the following error:

java.lang.IllegalStateException: Fragement no longer exists for key android:target_state: index 1

If I remove fragment C from the equation, the error goes away. It also doesn't crash if I load all fragments in their parent's fragmentManager (instead of childFragmentManager)

like image 817
Cigogne Eveillée Avatar asked Nov 03 '22 04:11

Cigogne Eveillée


1 Answers

The answer is absolutely yes. You can have 3 levels. using it successfully in my App.

like image 113
Sean Avatar answered Nov 08 '22 07:11

Sean