private synchronized void showFragment(Stack<Fragment> fragmentStack, Class cls, Bundle mBundle, String uuid) {
if (fragmentStack != fragmentMap.get(mViewDataBinding.rgRadioGroup.getCheckedRadioButtonId()))
return;
Fragment fragmentTarget = getSupportFragmentManager().findFragmentByTag(uuid);
FragmentTransaction tf = getSupportFragmentManager().beginTransaction();
if (fragmentTarget == null) {
fragmentTarget = fragmentNewInstance(cls, mBundle);
}
for (Fragment tmp : getSupportFragmentManager().getFragments()) {
if (tmp instanceof SupportRequestManagerFragment) {
continue;
}
String tag = tmp.getTag();
if (TextUtils.isEmpty(tag)) {
tag = UUID.randomUUID().toString();
try {
FieldUtils.writeField(tmp, "mTag", tag);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
if (tmp.getTag().equals(uuid)) {
continue;
}
tf.hide(tmp);
}
//不包含
if (fragmentStack.search(fragmentTarget) == -1) {
fragmentStack.push(fragmentTarget);
tf.add(R.id.fg_container, fragmentTarget, uuid).show(fragmentTarget);
} else {
//调整堆栈位置 栈顶元素问显示的fragment
fragmentStack.remove(fragmentTarget);
fragmentStack.push(fragmentTarget);
tf.show(fragmentTarget);
}
removeOtherStack(fragmentStack, tf);
tf.commitNowAllowingStateLoss();
}
网友评论