Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7537993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:59:48+00:00 2026-05-30T06:59:48+00:00

I am using my own html code to show a html page in WebView.

  • 0

I am using my own html code to show a html page in WebView. I want to close the current activity on click of Cancel Button.
My Code is like:

public class WebHtml extends Activity
{
        String historyUrl, baseUrl;
        URL url = null;
        WebView mWebView;

String html = "<html>" + 
                "<body>" +
                "<form id='form1' name='form1' method='post' action='get.html'>" +
                "User <input type='text' name='user'>   <br />" +
                "Password <input type='password' name='user'>   <br />" +
                "<input type='submit' name='Submit' value='Login' />" +
                "<input type='button' value='Cancel' name='Cancel' onClick='javascript:window.close();'' />" +
                "</form>" +
                "</body>" +
                "</html>";

public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
           // setContentView(R.layout.webview);
            mWebView = new WebView(this);
            mWebView.getSettings().setJavaScriptEnabled(true);  
            mWebView.loadDataWithBaseURL(baseUrl, html, "text/html", "utf-8", historyUrl);
            mWebView.setWebViewClient(new HelloWebViewClient());
            setContentView(mWebView);
        }

        @Override 
        public boolean onKeyDown(int keyCode, KeyEvent event) 
        { 
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) 
            { 
                mWebView.goBack();
                return true; 
            } 
            return super.onKeyDown(keyCode, event); 

        }

        private class HelloWebViewClient extends WebViewClient 
        { 
            public void onPageStarted(WebView view, String url, Bitmap bitmap)
            {
                Log.i("ShowForm", "onPageStarted()" + System.currentTimeMillis());
                historyUrl = url.toString();
            }
            public void onPageFinished(WebView view, String url)
            {
                Log.i("ShowForm", "onPageFinisheded()" + System.currentTimeMillis());
                baseUrl = url.toString();
            }

            @Override 
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            { 

                view.loadUrl(url);
                return true; 
            } 
        }
}

The thing is I am not able to make it close the current form activity. I had used (window.close(), form.close(), javascript:window.close() on onClick but they showed no effect) & (I tried window.unload() which made exception) Moreover System.exit() shuts the app off at the time activity first starts.

Please suggest me what should I do.

Thanks,

Haps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:59:49+00:00Added an answer on May 30, 2026 at 6:59 am

    Can you change the onClick of that cancel button to a URL? Something like onClick="document.location.href='http://exitActivity';".

    Then in your shouldOverrideUrlLoading method, you can intercept that URL and exit the app.

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        if (url.contains("http://exitActivity")
            finish();  // close activity
        else
            view.loadUrl(url);
    
        return true; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a Facebook-like autocomplete jquery library found at: http://otisbean.com/dropbox/jquery.tokeninput.js In my own html
I'd like to select the image source url from html code using javascript regexp.
I am using my own custom authentication with IIS, and I want the server
I can't get intellisense for my own html helpers. My CustomHtmlHelpers.cs looks like this:
i'm using ckEditor together with its own jQuery adapter and i'd like to define
I'm using an HTML document to show text output in my application - this
after using own custom cms for over 6 years, I decided to go for
I am using my own implementation of the UserDetailsService interface to load a User
I'm using my own class for database queries, extending mysqli: class iDatabase extends mysqli
I am using my own custom navigationBar, but i need to access it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.