'Back button in WebView not working correctly
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!
Solution 1:[1]
Remove your setonkeylistener and Add
@Override
public void onBackPressed() {
// super.onBackPressed(); Do not call super.onbackpressed!
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vijay S |
