1

I have an app that has a single activity where all the screens are displayed as fragments.

So when most of the times I am changing the fragment I add it to the back stack. So the BackStack can get quite big.

getActivity().getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.leftPane, new ReleaseFragmentBuilder(releaseId).build())
    .addToBackStack(null)
    .commit();

My question is if I want to replace a fragment but do not keep the BackStack anymore(BackStack Reset) , one option is to clear the BackStack by doing a PopBackStack until root (which is super inefficient and have seen other problems) OR to do a fragment replace WITHOUT adding it to the BackStack

getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.leftPane, new HomeFragment())
    .commit();

So What do you recommend? If I use only the replace , Does it have any memory issues?

JJD
  • 50,076
  • 60
  • 203
  • 339
Kenenisa Bekele
  • 835
  • 13
  • 34
  • so basically what is it you want to do? Do you want to remove the whole backstack upon doing this particular transaction? Or you just plainly don't want this replace transaction to be part of your backstack?? – Bhargav Aug 18 '15 at 11:38
  • You can find answer in simiar question here -> http://stackoverflow.com/a/23328086/1593476 – skrzatswat Aug 18 '15 at 12:24
  • @Bhargav , I want to remove the whole backstack. – Kenenisa Bekele Aug 18 '15 at 13:20
  • @skrzatswat , Well the answer there just shows how to clear the backstack, but my question is more of what is the difference of clearing the BackStack or just executing a replace on the current fragment without adding it. – Kenenisa Bekele Aug 19 '15 at 11:52

0 Answers0