美文网首页
Can not perform this action afte

Can not perform this action afte

作者: 菜鸟何时起飞 | 来源:发表于2020-06-12 10:41 被阅读0次

    Fragment 在显示或者隐藏,移除是出现Can not perform this action after onSaveInstanceState #解决办法:onSaveInstanceState方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后 再给它添加Fragment就会出错。解决办法就是把commit()方法替换成 commitAllowingStateLoss()

    try {
                var mDismissed: Field = DialogFragment::class.java.getDeclaredField("mDismissed")
                mDismissed.isAccessible = true
                mDismissed.set(this, false)
    
                var mShownByMe: Field = DialogFragment::class.java.getDeclaredField("mShownByMe")
                mShownByMe.isAccessible = true
                mShownByMe.set(this, true)
            } catch (e: Exception) {
                e.printStackTrace()
               
            }
            val ft: FragmentTransaction = manager.beginTransaction()
            ft.add(this, tag)
            ft.commitAllowingStateLoss()
    

    相关文章

      网友评论

          本文标题:Can not perform this action afte

          本文链接:https://www.haomeiwen.com/subject/tpkgtktx.html