在片段事务处理中已调用commit来获取异常

时间:2019-06-06 06:21:19

标签: android android-fragments fragmenttransaction

致命异常:java.lang.IllegalStateException:提交已被调用

片段事务高于异常情况

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.content_main, fragment);
       // fragmentTransaction.commit();

        try {
            fragmentTransaction.commit();
        } catch (IllegalStateException e) {
            fragmentTransaction.commitAllowingStateLoss();
        }

2 个答案:

答案 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();