OnBackInvokedCallback is not enabled for the application in Set ‘android:enableOnBackInvokedCallback=”true”‘ in the application manifest as warning

This is because of the Android Gesture Navigation, reference link here

To help make predictive back gesture helpful and consistent for users, we’re moving to an ahead-of-time model for back event handling by adding new APIs and deprecating existing APIs.

The new platform APIs and updates to AndroidX Activity 1.6+ are designed to make your transition from unsupported APIs (KeyEvent#KEYCODE_BACK and OnBackPressed) to the predictive back gesture as smooth as possible.

The new platform APIs include OnBackInvokedCallback and OnBackInvokedDispatcher, which AndroidX Activity 1.6+ supports through the existing OnBackPressedCallback and OnBackPressedDispatcher APIs.

You can start testing this feature in two to four steps, depending on your existing implementation.

  1. Upgrade to AndroidX Activity 1.6.0-alpha05. By upgrading your dependency on AndroidX Activity, APIs that are already using the
    OnBackPressedDispatcher APIs such as Fragments and the Navigation
    Component will seamlessly work when you opt-in for the predictive back
    gesture.
  // In your build.gradle file:
    dependencies {

  // Add this in addition to your other dependencies
  implementation "androidx.activity:activity:1.6.0-alpha05"
  1. Opt-in for the predictive back gesture. Opt-in your app by setting the EnableOnBackInvokedCallback flag to true at the application level
    in the AndroidManifest.xml.
<application

    ...

    android:enableOnBackInvokedCallback="true"

    ... >

...

</application>

If your app doesn’t intercept the back event, you’re done at this
step. Note: Opt-in is optional in Android 13, and it will be ignored
after this version.

 val onBackPressedCallback = object: OnBackPressedCallback(true) {

   override fun handleOnBackPressed() {

     // Your business logic to handle the back pressed event

   }

 }

 requireActivity().onBackPressedDispatcher

   .addCallback(onBackPressedCallback)
  1. When your app is ready to stop intercepting the system Back event, disable the onBackPressedCallback callback.
onBackPressedCallback.isEnabled = webView.canGoBack()

Note: Your app may require using the platform APIs
(OnBackInvokedCallback and OnBackPressedDispatcher) to implement the
predictive back gesture. Read our documentation for details.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)