0

I need to update the old fragment in the Fragment list, so I need to clear all the old style.

 getSupportFragmentManager().beginTransaction().add() 

method could add fragment to the list, but how to clear all the fragment once for all ?

Add

 android.support.v4.app.Fragment fragment = getSupportFragmentManager()
       .findFragmentByTag(tag);

    if (fragment == null) {
        Log.d("Main",tag+"fragment == null");

        fragment = new FragmentFactory().getFragment(tag);

        getSupportFragmentManager().beginTransaction().hide(currentFragment)
       .add(R.id.content_frame, fragment, tag).commit();
        currentFragment = fragment;
    } else if (fragment.isHidden()) {
        Log.d("Main",tag+"fragment.isHidden()");  
        getSupportFragmentManager().beginTransaction()
       .hide(currentFragment).show(fragment).commit();
        currentFragment = fragment;
    }

As the answer

fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

its still existing bug, when the second round of the if statement it goes into the else. But as the purpose fragment should be cleared. The if statement need to go if branch and add new fragment. How to fix it?

Eva
  • 332
  • 2
  • 13

1 Answers1

0

Try this :

fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46
  • What is null's meaning? – Eva Nov 23 '15 at 12:39
  • i have found no proper documentation for this.what i can say this at this place of ''null'' fragment tag is passed to pop the related fragment.like.. if (tag.equals("4thfragment")) { if (fragmentManager.getBackStackEntryCount() != 0) { fragmentManager.popBackStack("3rdfragment", FragmentManager.POP_BACK_STACK_INCLUSIVE); } } – SinghIsBling Nov 24 '15 at 10:39