//重写DialogFragment的show方法
//可以查看showAllowingStateLoss不过被hide
//通过反射拿到这两个变量进行设置
try {
val mDismissed = DialogFragment::class.java.getDeclaredField("mDismissed")
mDismissed.isAccessible = true
mDismissed.set(this, false)
val mShownByMe = DialogFragment::class.java.getDeclaredField("mShownByMe")
mShownByMe.isAccessible = true
mShownByMe.set(this, true)
manager.beginTransaction()
.add(this, tag)
.commitAllowingStateLoss()
}
} catch (e: Throwable) {
LogUtils.eTag(TAG, e.toString())
}
网友评论