how to handle back button in webview android

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                } else {
                    finish();
                }
                return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
android studio webview back button how to call back button from android and get response from webview back in webview android android webview capture back button fragment android webview capture back button android webview back button fragment android webview in fragment back button ios webview add back button webview on back pressed android webview handle back button how to add a back button in a webview webview.back() webview back hardware back, history back rN webvoew how to back page on webview getting the response how to do back button in android studio android back button when new activity apply back pressed on webview android pressing bak nuton on webview android closes webview android webview on back pressed front and back option webview working android studio goto last activity that webview was clicked from call back button webview On click back go back to first page webview webview back button android android webview previous page android studio on back pressed webview to go previous page in android webview 3 back buttons required webview on back pressed how to go back in webview in android if (webView.canGoBack()){ webView.goBack(); onbackpress webview android webview back android webview back key webview goback() webview android back button go back in webview android back press webview android not working webview back button back press webview android how to back in webview in android from one webpage to another web view all backpreess hanlded in kotlin web view all backpreess hanlded all back press handle in webview android how to handle back press in webview android webview back button in android back button is calling history back instead of closing webview android press back button webview android webview. go back android android webview back page android studio back button webview webview goback android android webview back press webview on back pressed listener android how to back press in webview android how to go back in android webview android webview back button onbackpressed android webview webview go back when back button pressed android how to handle back button in webview android
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source