Skip to content

Instantly share code, notes, and snippets.

@KaustubhPatange
Last active February 8, 2023 16:37
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 KaustubhPatange/a3a0c5b40242483b9c189b231fa341ac to your computer and use it in GitHub Desktop.
Save KaustubhPatange/a3a0c5b40242483b9c189b231fa341ac to your computer and use it in GitHub Desktop.
class MainActivity ... {
override fun onCreate(...) {
// This will work but has a catch. Do not implement this,
onBackPressedDispatcher.addCallback(object: OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (shouldFinish()) {
this.remove()
onBackPressed()
onBackPressedDispatcher.addCallback(this)
}
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment