If you look at your code as soon as the shouldOverrideUrlLoading method shouldOverrideUrlLoading called based on some logic for a specific URL action, you need the Webview method back. I suggest you use the following method inside an action:
@Override public void onBackPressed() { if ((keyCode == KeyEvent.KEYCODE_BACK) && web1.canGoBack()) { webview.goBack(); } else { super.onBackPressed(); } }
which does the same as onKeypressed. (It uses onBackPressed instead of onKeypressed , but write this code inside the Activity class, but not inside the custom WebViewClient .
Call onBackPressed() inside shouldOverrideUrlLoading . Try this should work.
source share