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.

Advertisements

Java Code to Enable Webview go to back page in Android

@Override
   public void onBackPressed() {


       if (webView.canGoBack()) {
           webView.goBack();

       } else {

           finish();
       }}

 

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

webView.goForward();

 

,

Post navigation

Comments

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