0

For Example:

Fragment prevFragment = getSupportedFragmentManager().findFragmentById(R.id.container);
getSupportedFragmentManager()
    .beginTransaction()
    .hide(prevFragement)
    .add(R.id.container, fragment, null)
    .commit();
Jeffrey
  • 1,998
  • 1
  • 25
  • 22
  • doesn't really sound like a good idea, keeping potentially irrelevant code in memory, even if a fragment isn't visible it will still go through lifecycle events – a_local_nobody May 17 '21 at 13:35
  • 3
    Does this answer your question? [Android Fragments: When to use hide/show or add/remove/replace?](https://stackoverflow.com/questions/13149446/android-fragments-when-to-use-hide-show-or-add-remove-replace) – Jeffrey May 17 '21 at 22:47

0 Answers0