Skip to content

Instantly share code, notes, and snippets.

@raxhaxor
Created December 31, 2020 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raxhaxor/961e3831cfd236fb102127a93882d1c5 to your computer and use it in GitHub Desktop.
Save raxhaxor/961e3831cfd236fb102127a93882d1c5 to your computer and use it in GitHub Desktop.
commitAllowingStateLoss on DialogFragment
override fun show(manager: FragmentManager, tag: String?) {
try {
val superClass = this::class.java.superclass
val dismissedField = superClass?.getDeclaredField("mDismissed")
val isShownByMeField = superClass?.getDeclaredField("mShownByMe")
dismissedField?.isAccessible = true
isShownByMeField?.isAccessible = true
dismissedField?.setBoolean(this, false)
isShownByMeField?.setBoolean(this, true)
dismissedField?.isAccessible = false
isShownByMeField?.isAccessible = false
val ft = manager.beginTransaction()
ft.add(this, tag)
ft.commitAllowingStateLoss()
}catch(e: Exception){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment