When the back button is pressed in webview the app exit
I had many hours wasted on this one lately. Please look closely. WebView Docs shouldoverrideUrlLoading
If a WebViewClient is provided, returning true causes the current WebView to abort loading the URL, while returning false causes the WebView to continue loading the URL as usual.
So the shouldOverrideUrlLoading return should be false, note true. True will force both disable the onbackpress override method ( i think) and loading further Urls.
So the code should be like:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){//condition or the code
view.loadUrl(url);
return false;
}
});
also I used :
@Override
public void onBackPressed() {
if (webview.canGoBack()) {
webview.goBack();
} else {
super.onBackPressed();
}
}
hope I this will help in future!
Have you tried it in onBackPressed()
like:
@Override
public void onBackPressed() {
if (mywebView.isFocused() && mywebView.canGoBack()) {
mywebView.goBack();
} else {
super.onBackPressed();
}
}