Created
October 29, 2022 13:18
-
-
Save hamurcuabi/874c9298c3a197e4aaaf5bedb1624910 to your computer and use it in GitHub Desktop.
Without Delegation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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