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 8738353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:42:56+00:00 2026-06-13T10:42:56+00:00

I have this code in my app: public class Home extends Activity{ @Override public

  • 0

I have this code in my app:

public class Home extends Activity{
@Override 
public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.home);
    final ProgressDialog progressBar;
    if(isOnline()){
        WebView webView = (WebView) findViewById(R.id.home_web);
        webView.setBackgroundColor(Color.parseColor(getString(R.color.colore_bg)));
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setPluginsEnabled(true);
        webView.setWebViewClient(new MyWebViewClient());
        progressBar = ProgressDialog.show(this,getString(R.string.caricamento),getString(R.string.attendere));
        webView.setWebViewClient(new WebViewClient(){
            public void onPageFinished(WebView view, String url) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }
        });
        webView.loadUrl("http://www.mysite.com/android.php");
    }else{
        Toast.makeText(this,getString(R.string.no_connessione),Toast.LENGTH_LONG).show();
    }
}
private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
            System.out.println("here");
        if (Uri.parse(url).getHost().equals("mysite.com")) {
            // This is my web site, so do not override; let my WebView load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
}
public boolean isOnline(){
    ConnectivityManager cm=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if(ni==null){
        return false;
    }
    return ni.isConnected();
}
}

The shouldOverrideUrlLoading doesn’t work, neither print the system.out, it seems to be never called. How can I repair this? I need to open all the link (except the main page http://www.mysite.com/iphone.php) in the default browser

  • 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-06-13T10:42:57+00:00Added an answer on June 13, 2026 at 10:42 am

    You’ve set the WebViewClient twice, thus replacing the first one (shouldOverrideUrlLoading) with the second one (onPageFinished). Combine the two for it to work:

    public class Home extends Activity{
    private ProgressDialog progressBar;
    
    @Override 
    public void onCreate(Bundle savedInstanceState){ 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.home);
        if(isOnline()){
            progressBar = ProgressDialog.show(this,getString(R.string.caricamento),getString(R.string.attendere));
            WebView webView = (WebView) findViewById(R.id.home_web);
            webView.setBackgroundColor(Color.parseColor(getString(R.color.colore_bg)));
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setBuiltInZoomControls(true);
            webView.getSettings().setPluginsEnabled(true);
            webView.setWebViewClient(new MyWebViewClient());
            webView.loadUrl("http://www.mysite.com/android.php");
        }else{
            Toast.makeText(this,getString(R.string.no_connessione),Toast.LENGTH_LONG).show();
        }
    }
    
    private class MyWebViewClient extends WebViewClient {
    
        @Override
        public void onPageFinished(WebView view, String url) {
            if (progressBar != null && progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }
    
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                System.out.println("here");
            if (Uri.parse(url).getHost().equals("mysite.com")) {
                // This is my web site, so do not override; let my WebView load the page
                return false;
            }
            // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    }
    }
    

    (Please ignore the bad formatting :p)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
I have this code //file Globals.cs in App_Code folder public class Globals { public
I have a DashBoardController.cs here i have this code public class DashBoardController : Controller
I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
I have this code: app = new Application(); app.Visible = false; workbook = app.Workbooks.Add(1);
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I am creating a rails app and have used this code in one of
I have a app/helpers/application_helper.rb file with this code: def clippy(text, bgcolor = #ffffff) text.gsub!('',')
I found this PHP code in an app I have to modify... $links =
This is my current scenario: I have checked in my grails app code +

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.