KeyEvent) { fi nal KeyEvent event = (KeyEvent) q.mEvent; // If the new back dispatch is enabled, intercept KEYCODE_BACK before it reaches the // view tree or IME, and invoke the appropriate {@link OnBackInvokedCallback}. if (isBack(event) && mContext != null && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) { OnBackInvokedCallback topCallback = getOnBackInvokedDispatcher().getTopCallback(); if (event.getAction() == KeyEvent.ACTION_UP) { if (topCallback != null) { topCallback.onBackInvoked(); return FINISH_HANDLED; } } // .. } } } https://shorturl.at/jCGUV
onBackPressedDispatcher.addCallback(enabled = true) { // Do your custom stuff here.. } // remove the callback from onBackPressedDispatcher callback.remove()
onBackPressedDispatcher.addCallback(enabled = true) { // Do your custom stuff here.. } // remove the callback from onBackPressedDispatcher callback.remove() // update the enable state callback.isEnabled = true
onBackPressedDispatcher.addCallback(enabled = true) { // Do your custom stuff here.. } // remove the callback from onBackPressedDispatcher callback.remove() // update the enable state callback.isEnabled = true // check if any enabled callbacks exists onBackPressedDispatcher.hasEnabledCallbacks()