Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android API 33 , New Back Pressed Dispatcher. #1

Open
m-anshuman2166 opened this issue Aug 2, 2023 · 0 comments
Open

Android API 33 , New Back Pressed Dispatcher. #1

m-anshuman2166 opened this issue Aug 2, 2023 · 0 comments

Comments

@m-anshuman2166
Copy link

Adapt to onBackPressed event to work on both the latest and old versions of Android. Since API 33, OnBackInvokedDispatcher is the ideal way to handle that.

Ref : https://developer.android.com/reference/android/window/OnBackInvokedDispatcher

Ideal Approach:

private val onBackPressedCallback: OnBackPressedCallback =
        object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
               // Do your stuff
            }
        }

if (Build.VERSION.SDK_INT >= 33) {
            onBackInvokedDispatcher.registerOnBackInvokedCallback(
                OnBackInvokedDispatcher.PRIORITY_DEFAULT
            ) {
                // Do your stuff
            }
        } else {
            onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
        }
@m-anshuman2166 m-anshuman2166 changed the title Android 33 Api, New Back Pressed Dispatcher. Android API 33 , New Back Pressed Dispatcher. Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant