Try to return shouldOverrideUrlLoading true
Here is the explanation: -
True, if the host application wants to leave the current WebView and process the URL itself, otherwise it will return false. Reference
So this should do the trick,
public boolean shouldOverrideUrlLoading(WebView view, String url) { // do some html modifcations (myhtml) view.loadDataWithBaseURL(url, myhtml, "text/html", "utf-8", url); return true; }
And treat backPressed() as -
@Override public void onBackPressed() { if (webview != null && webview.canGoBack()) { webview.goBack(); } else { super.onBackPressed(); } }
source share