`
wsyuzx
  • 浏览: 27997 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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();
  
     
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics