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

  • SEARCH
  • Home
  • 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 6674137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:42:37+00:00 2026-05-26T03:42:37+00:00

I want to have a button press display a web page, I use the

  • 0

I want to have a button press display a web page, I use the standard approach with a WebViewClient and WebChromClient like so:

final Button revsButton = (Button) this.findViewById(R.id.buttonReviews);
revsButton.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        wb.setWebViewClient(new ShareWebViewClient());  
        wb.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                activity.setTitle("Loading Reviews...");
                activity.setProgress(progress * 100); 
                if(progress == 100)
                    activity.setTitle(R.string.app_name);
            }
        });
        wb.getSettings().setJavaScriptEnabled(true);  
        wb.loadUrl(revString );  
        setContentView(wb);                         
    }
}); 


private class ShareWebViewClient extends WebViewClient {  
    public boolean shouldOverrideUrlLoading(WebView view, String url) {   
        view.loadUrl(url);   
        return true;  
    } 
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
          Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
      }
} 

This is all working great, the thing is when I press the Back button it exits my Activity entirely and returns to the previous page. What I really want the back button to do is to close the WebViewClient and return to the dispaly with the button on it. This is what I tried to do so far which half worked — it didn’t leave the activity, but the activity page was just a blank screen instead of showing the controls that should be on there.

@Override
public void onBackPressed() {
    if (wb.getVisibility() == View.VISIBLE) {
        wb.setVisibility(View.INVISIBLE);
    } else {
        finish();
    }
}
  • 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-26T03:42:38+00:00Added an answer on May 26, 2026 at 3:42 am

    I suppose this happens because you’re using WebViewClient rather than launching browser using standard:

    Uri uri=Uri.parse(urlString);
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    activity.startActivity(intent);
    

    In this case BACK button would close browser activity and you’ll get back your primary activity.

    In your case I would propose in onBackPressed() – restore your original content selecting

    setContentView(my_original_layout);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to have a Hyperlink-Button in a gridView in which I can display a
I have a button I want to use in the beginning and the end
i have a Button on a HTML page . i want to attach file
I simply want to display a CreditsView. So if i press a button show
I want when i press a specific Button an Image (like a map) to
I want to have a button that has numbers in the range 0 ...
In my Delphi Project i want to have a 'Settings' button that when clicked,
I have a button on my MasterPage and I want the ContentPage to handle
I have a button that when i tap on it i want to invoke
I have two button name A, and B want to click them equal to

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.