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

@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();

 

Related Posts

Fix Plugin [id: ‘com.android.application’, version: ‘7.1.3’, apply: false] was not found in any of the following sources

Here is how to fix Plugin [id: ‘com.android.application’, version: ‘7.1.3’, apply: false] was not found in any of the following sources This error is caused by mismatching…

Get Age from Date of Birth in Java Android

Here is how to get a user’s age from date of birth If you need get a user’s age from a given date of birth string, this…

How to Check if String Array Contains a Specific String in Android

Here is how to get a specific value or String from Array in Android To check if a string array contains a specific string, you can use…

Make Android WebView Support Razorpay Payment

How to Support Razorpay Payment and UPI in Android WebView? Android webview is inexpensive and easy way to make apps for websites. But to support some specific…

Make Android Webview Support PayTM Google Pay PhonePe UPI

GooglePay, Phonpe and PayTM support in Android WebView If you have built an android app for your new ecommerce website or any other website that needs accept…

Leave a Reply

Your email address will not be published.