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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:25:20+00:00 2026-06-01T07:25:20+00:00

I’ve in the following code the progressbar working on the first page load. after

  • 0

I’ve in the following code the progressbar working on the first page load. after when I click on other links, the progrss bar is not shown ?

If somebody can tell me how to change this code to have the progress bar working on all loading ?

Thanks,

André.

public class Android_Activity extends Activity {
WebView webview;

@Override
protected void onSaveInstanceState(Bundle outState) {
    WebView webview = (WebView) findViewById(R.id.webview);
    webview.saveState(outState);
}   

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set the main content view
    setContentView(R.layout.main);

    // check if an instance is stored and so restore it
    if (savedInstanceState != null){
        ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
    }

    final ProgressDialog progressBar = ProgressDialog.show(this, getString(R.string.progress_title),
            getString(R.string.progress_msg));

    webview = (WebView)findViewById(R.id.webview);
    webview.setHttpAuthUsernamePassword(getString(R.string.kdg_host),
            getString(R.string.kdg_realm),
            getString(R.string.kdg_user_name),
            getString(R.string.kdg_password)
            );
    //webview.setWebViewClient(new myWebViewClient());
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webview.getSettings().setRenderPriority(RenderPriority.HIGH);
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webview.getSettings().setAllowFileAccess(true);
    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        public void onPageStarted(WebView view, String url) {
            if (!progressBar.isShowing()) {
                progressBar.show();
            }
        }           
        public void onPageFinished(WebView view, String url) {
            //super.onPageFinished(view, url);
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }           
    });

    webview.loadUrl(getString(R.string.base_url));
}

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

private class myWebViewClient extends WebViewClient {   
    @Override       
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        boolean error = false;          

        // check if it's an MAILTO URL
        if(url.substring(0, 6).equalsIgnoreCase("mailto")){
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent .setType("plain/text");
            emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{url.substring(7)});
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));   
            return true;
        }
        // check if it's an EXT:// (Call Web Browser)
        else if(url.substring(0, 6).equalsIgnoreCase("ext://")){
            Uri uriUrl = Uri.parse(url.substring(6));
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); 
            startActivity(launchBrowser);   
            return true;
        }               
        // check if it's an RTSP URL
        else if(url.substring(0, 4).equalsIgnoreCase("rtsp")){
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
            return true;
        }
        // else if it's an MP4 file link
        else if(url.endsWith(".mp4")){
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "video/mp4");
            startActivity(intent);
            return true;
        }
        // else if it's a 3GP file link
        else if(url.endsWith(".3gp")){
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "video/3gp");
            startActivity(intent);
            return true;
        }
        // else if it's a MP3 file link
        else if(url.endsWith(".mp3")){
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri, "audio/mp3");
            startActivity(intent);
            return true;
        }               
        // else if it's a page URL
        else{
            URL Url;
            try {
                Url = new URL(url);
                HttpURLConnection httpURLConnection = (HttpURLConnection) Url
                        .openConnection();
                int response = httpURLConnection.getResponseCode();
                if ((response >= 200)&&(response < 400))
                    //view.loadUrl(url);
                    error = false;
                else
                    error = true;
            } catch (Exception e) {
                error = true;
            }
        }

        // if an error occurred
        if (error) {
            showErrorDialog();
        }

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

@Override
public void onResume() {
    super.onResume();
    webview.reload();
}   

public void onReceivedError(WebView view, int errorCode,
        String description, String failingUrl) {
    showErrorDialog();
}

public void showErrorDialog(){
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.error_title));
    alertDialog.setMessage(getString(R.string.error_msg));
    alertDialog.setButton(getString(R.string.ok_btn),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int which) {
                }
            });
    alertDialog.show();
}
}
  • 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-01T07:25:21+00:00Added an answer on June 1, 2026 at 7:25 am

    Use below working code ::

    public class Android_Activity extends Activity {
    private Android_Activity _activity;
        @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);     
                getWindow().requestFeature(Window.FEATURE_PROGRESS);
                _activity = this;   
                setContentView(R.layout.main);
    
                mwebview=(WebView)view.findViewById(R.id.webview);
                mwebview.getSettings().setJavaScriptEnabled(true);
                mwebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    
                if(checkInternetConnection(_activity)==true){
                    if(savedInstanceState==null)
                        mwebview.loadUrl(URL);
                    else
                        mwebview.restoreState(savedInstanceState);
                }
                else{
                    AlertDialog.Builder builder = new AlertDialog.Builder(_activity);
                    builder.setMessage("Please check your network connection.")
                           .setCancelable(false)
                           .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
    
                               }
                           });
    
                    AlertDialog alert = builder.create();    
                    alert.show();
                }
                mwebview.setWebChromeClient(new WebChromeClient() {
    
                    @Override
                    public void onProgressChanged(WebView view, int progress) { 
                        if(mwebview.getVisibility()==View.VISIBLE)
                        {
                            _activity.setProgress(progress * 100);
                        }
                    }
                });
                mwebview.setWebViewClient(new HelloWebViewClient());
            }
    
    
            //HelloWebViewClient class for webview
            private class HelloWebViewClient extends WebViewClient {
    
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    // TODO Auto-generated method stub
                    super.onPageStarted(view, url, favicon);
                }
                @Override
                public void onReceivedError(WebView view, int errorCode,
                        String description, String failingUrl) {
                    // TODO Auto-generated method stub
                    super.onReceivedError(view, errorCode, description, failingUrl);
    
                }
                @Override
                public void onPageFinished(WebView view, String url) {
                    // TODO Auto-generated method stub
                    super.onPageFinished(view, url);
                }
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
                    view.loadUrl(url);
                    return true;
                }
    
            }   //HelloWebViewClient-class
            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {
                // Check if the key event was the Back button and if there's history
                if ((keyCode == KeyEvent.KEYCODE_BACK) && mwebview.canGoBack() ){
                    mwebview.goBack();
                    return true;
                }
                // If it wasn't the Back key or there's no web page history, bubble up to the default
                // system behavior (probably exit the activity)
                return super.onKeyDown(keyCode, event);
            }
            //To check whether network connection is available on device or not
                public static boolean checkInternetConnection(Activity _activity) {
                    ConnectivityManager conMgr = (ConnectivityManager) _activity.getSystemService(Context.CONNECTIVITY_SERVICE);
                    if (conMgr.getActiveNetworkInfo() != null
                            && conMgr.getActiveNetworkInfo().isAvailable()
                            && conMgr.getActiveNetworkInfo().isConnected()) 
                        return true;
                    else
                        return false;
                }//checkInternetConnection()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.