3

As per my requirement for app I have added Child Fragments inside MainFragment, which extends Fragment like below code dynamically on conditions after getting server response:

DetailsImageFragment imgFragment = DetailsImageFragment.newInstance();
FragmentTransaction ft = getChildFragmentManager()
.beginTransaction();
ft.add(R.id.thisFragmentLayout, imgFragment).commit();

Everything works fine but when I call other fragment from this fragment with replace() by another fragment as follows:

FragmentManager fm = getSupportFragmentManager();
SecondFragment categoryFragment = SecondFragment.newInstance();
fm.beginTransaction()
    .replace(R.id.contentFrame, categoryFragment).addToBackStack(null)
    .commit();

It well replaces this second Fragment.

But when I press Back Button, MainFragment reloads all Child Fragments again. With this, I am facing a performance issue on back visit. It's taking a lot of time to reload previous MainFragment.
Can any one help me out of this issue? Your help will be appreciate.

Blo
  • 11,903
  • 5
  • 45
  • 99
Ashish Wadatkar
  • 427
  • 2
  • 5
  • 19

0 Answers0