我在我的 Android 应用程序中使用了TabListener
与此类似的应用程序:http: //developer.android.com/guide/topics/ui/actionbar.html#Tabs
我的onTabSelected
实现:
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Fragment preInitFrag = mActivity.getFragmentManager().findFragmentByTag(mTag);
if (preInitFrag == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(preInitFrag);
}
}
每次选择选项卡时,我都想将其添加到后台堆栈。我怎样才能做到这一点?使用参数ft
with ft.addToBackStack("test")
,它不起作用。它抛出一个致命的异常:
java.lang.RuntimeException:
Unable to start activity ComponentInfo{.../...BaseActivity}:
java.lang.IllegalStateException:
This FragmentTransaction is not allowed to be added to the back stack.