致命异常:java.lang.IllegalStateException:提交已被调用
片段事务高于异常情况
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_main, fragment);
// fragmentTransaction.commit();
try {
fragmentTransaction.commit();
} catch (IllegalStateException e) {
fragmentTransaction.commitAllowingStateLoss();
}
答案 0 :(得分:-1)
这会有所帮助。
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.addToBackStack(null);
transaction.commit();
答案 1 :(得分:-1)
要加载片段,请使用此。.
Fragment fragment = new MyFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frame_layout, fragment).commit();