0

I want to use the back button of Android to go back into a WebView (it's in a Fragment), so I put up this code in Kotlin:

catWebView.setOnKeyListener { _, keyCode, _ ->
    if (keyCode == KeyEvent.KEYCODE_BACK && catWebView.canGoBack()) {
        catWebView.goBack()
    }
    return@setOnKeyListener true
}

and that works, but with a problem: when I tap the back button, the WebView goes all the way back to the first page opened, and not by single steps...

How can I solve it? Thank you!

1 Answers1

2

Remove your setonkeylistener and Add

 @Override
    public void onBackPressed() {
        // super.onBackPressed(); Do not call super.onbackpressed!
  
    }
Vijay S
  • 358
  • 3
  • 10