我想在序列f1,f2,f3中添加片段到后面的堆栈...如果我从f3或f2开始我应该到达f1然后在backstack中没有任何内容。 这是我使用的代码:
public void openFragment(BaseFragment baseFragment, Bundle data) {
if (baseFragment != null) {
if (data != null)
baseFragment.setArguments(data);
Log.d(TAG, "openFragment" + baseFragment);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
String tag1 = getString(baseFragment.getTitleResourceId());
ft.replace(R.id.fragment_main, baseFragment, tag1);
ft.addToBackStack(null);
ft.commit();
if (baseFragment.getTitleResourceId() > 0)
mCurrentTitle = baseFragment.getTitleResourceId();
}
}
我尝试使用以下但没办法:
public void openFragment(BaseFragment baseFragment, Bundle data) {
if (baseFragment != null) {
if (data != null)
baseFragment.setArguments(data);
Log.d(TAG, "openFragment" + baseFragment);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
String tag1 = getString(baseFragment.getTitleResourceId());
// Fragment frgExist = fragmentManager.findFragmentByTag(tag1);
ft.replace(R.id.fragment_main, baseFragment, tag1);
// if (frgExist == null)
ft.addToBackStack(null);
ft.commit();
if (baseFragment.getTitleResourceId() > 0)
mCurrentTitle = baseFragment.getTitleResourceId();
}
}
* BaseFragment只是抽象类扩展片段,用于设置标题。 感谢。