android---android2.2与android4.0以上---getSupportFragmentManager

      FragmentManager
   在android2.2api与android4.0以上的api有着兼容性问题
如果使用android2.2api来开发使用
  FragmentManager fm=getSupportFragmentManager();
fm.beginTransaction().detach(mContent).commit();
   这样书写在android2.2api上没有问题
    但在android4.0以上则会报错 
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    查看各方面的资料发现以下这个可以解决

   FragmentManager fm=getSupportFragmentManager();
fm.beginTransaction().detach(mContent).commitAllowingStateLoss();
// getSupportFragmentManager().beginTransaction().detach(mContent)
// .commitAllowingStateLoss();
mContent = fragment;
fm.beginTransaction().attach(fragment)
.commitAllowingStateLoss();
  主要就是commit()方法改为commitAllowingStateLoss();
  
     

猜你喜欢

转载自wsyuzx.iteye.com/blog/1931488