IllegalStateException的终极修复:在onSaveInstanceState

时间:2016-07-05 22:33:21

标签: android android-fragments illegalstateexception

我了解到这是一个困扰2015年之前支持库版本的错误。 可惜!这是2016年,IllegalStateException: Can not perform this action after onSaveInstanceState在我打电话时仍然会崩溃我的应用程序 片段上的.show.commit.dismiss

我已经阅读了这个solution并且我的应用必须经常失败第三条规则避免在异步回调方法中执行事务因为我必须在Volley'中提交或解除片段onErrorResponse。

我尝试了以下解决方案:

  1. 尝试捕获错误:我尝试使用.show

    try { tagCatFragment.show(getSupportFragmentManager(), "TagCAatFragment");
             } catch (IllegalStateException e) {
                 e.printStackTrace();
             }
    
  2. 问题是对话框第一次显示。之后,对话框拒绝显示。

    1. 删除对super.onSaveInstanceState的调用片段的状态拒绝保存。

    2. .dismissAllowingStateLoss();和.commitAllowingStateLoss(); 到目前为止,我还没有看到任何问题。但我无法使用.show来电。

    3. 请你有更好的解决方案吗?

      我正在考虑使用FragmentManager而不是supportFragmentManager,因为我的应用支持API 16+,但我不知道这是否是一个非常好的解决方案。

0 个答案:

没有答案