我已经制作了一个静态函数来更改片段
/**
* This will replace fragment with current fragment
*
* @isAddToBackStack if it is true means when you pressback that caller
* fragment will come
* @bundle If you want to pass any value from one fragment to another
* fragment then pass value over here using Bundle
*/
public static int callFragment(Activity mActivity, Fragment mFragment,
boolean isAddToBackStack, Bundle bundle) {
FragmentManager fragmentManager = mActivity.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
if (bundle != null) {
mFragment.setArguments(bundle);
}
fragmentTransaction.replace(R.id.changeFragment, mFragment);
if (isAddToBackStack) {
return fragmentTransaction.addToBackStack("").commit(); //----------EXECUTING
} else {
return fragmentTransaction.commit(); //----------EXECUTING
}
}
我通过以下方法调用上面的函数
Constants.callFragment(MainActivity.this,
new MyContactFragment(), true, null);
但我已将调试指针放到调试应用程序中,我已经看到了 有时这个if和else两个语句都在执行
if (isAddToBackStack) {
return fragmentTransaction.addToBackStack("").commit(); //----------EXECUTING
} else {
return fragmentTransaction.commit(); //----------EXECUTING
}
如果有人知道请告诉我我在做什么错误