Last active
July 5, 2021 13:06
-
-
Save gokmenbayram/4097c4c72c37ac3844fbed0c5ed8065a to your computer and use it in GitHub Desktop.
OnBackPressedFrament.kt
This file contains hidden or 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
import android.content.Context | |
import androidx.activity.OnBackPressedCallback | |
import androidx.annotation.NonNull | |
import androidx.fragment.app.Fragment | |
class OnBackPressedFrament : Fragment() { | |
override fun onAttach(@NonNull context: Context) { | |
super.onAttach(context) | |
val callback = object : OnBackPressedCallback(true) { | |
override fun handleOnBackPressed() { | |
// do something. | |
} | |
} | |
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment