Make Webview Go to Back Page in Android

How to go to back page or forward page in Webview android Java

The android webview can go back and forward pages depending on the user selection.  It should be assigned on the device’s back button (Hardware button) and this is a very important feature that every webview app must have.

Without the assigning of this feature, your webview app will exit when the user taps on the back button, so here is the code to fix the issue, it is assigned on the OnBackPressed method.

Java Code to Enable Webview go to back page in Android

   public void onBackPressed() {

       if (webView.canGoBack()) {

       } else {



Explanation: This code makes the webview go to the previous page in the history pages that you visited in the webview, if the history page not availabe or no history, the activity will be closed or the app will be exited

And here is the code to make the Webview go to forward page




Post navigation


This site uses Akismet to reduce spam. Learn how your comment data is processed.