I am developing Android App. In a single activity I am replacing fragments. After some iterations my app gets closed without any force close message and no exception.
While searching I got one thing. If I track number of fragments on fragment manager using
getSupportFragmentManager().getFragments().size()
it keeps on incrementing while there is only one fragment which is active and no fragment present in back stack as I am replacing fragments.
Example :
- Frag 1 > Frag 2: No of fragments is 2
- Frag 1 > Frag 2 > Frag 3: No of fragments is 3
- Frag 1 > Frag 2 > Frag 3 > Frag 2 > Frag 1: No of fragments is 3
Here is code which I am using for fragment transaction:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content, fragmentStep1,
ApplicationTags.FRAGMENT_TAG_PAGE_1)
.disallowAddToBackStack().commit();
getFragmentManager().executePendingTransactions();
I need to remove all these fragments from fragentmanager for reducing memory usage by app.
Please help me with this one. Thanks in advance.