Skip to content

Instantly share code, notes, and snippets.

@hamurcuabi
Created October 29, 2022 13:18
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 hamurcuabi/874c9298c3a197e4aaaf5bedb1624910 to your computer and use it in GitHub Desktop.
Save hamurcuabi/874c9298c3a197e4aaaf5bedb1624910 to your computer and use it in GitHub Desktop.
Without Delegation
class HomeFragment : Fragment() {
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
// On back pressed
}
}
override fun onResume() {
super.onResume()
activity?.onBackPressedDispatcher?.addCallback(onBackPressedCallback)
}
override fun onStop() {
super.onStop()
onBackPressedCallback.remove()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment