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?