Question

I have used progress bar to indicate page is loading in android webview. But the Progress Bar is showing for ever even after the page has been loaded completely. I used logcat for debugging which shows onPageFinished function is called.

     @Override
   public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // TODO Auto-generated method stub
    _dialog =ProgressDialog.show(UmlScreen.this, "", "Please wait...");
    super.onPageStarted(view, url, favicon);
    _dialog.setCanceledOnTouchOutside(true);
    Log.d("LOGCAT", "started");
   }
   @Override
   public void onPageFinished(WebView view, String url) {
    // TODO Auto-generated method stub
    super.onPageFinished(view, url);
    if (_dialog != null || _dialog.isShowing()) {
            _dialog.dismiss();
            Log.d("LOGCAT", "finished");
        }

   }
Was it helpful?

Solution

Try initialization of _dialog outside WebViewClient such as in OnCreateView method

OTHER TIPS

Because the page is not finished. May be the page have a lot of images so it is taking time to download them. you can check it using break point. debug you code and put break point at super.onPageFinished(view, url);

I can give you some dummy codes.

webview.load(url);
dialog.show();

 public void onPageFinished(WebView view, String url) {
    //....
    dialog.dismiss();
 }
@Override
    public void onPageFinished(WebView view, String url) {

        try{
                if (prDialog.isShowing()|| prDialog!= null) {
                    prDialog.dismiss();
                    prDialog= null; /*** Add ***/
                }

                }catch(Exception exception){
                    exception.printStackTrace();
                }

        }
    }

Or visit... https://stackoverflow.com/a/31981161/3857542

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top