PrgressDialog when load a WebView crash issue

Posted by AndreaF on Stack Overflow See other posts from Stack Overflow or by AndreaF
Published on 2013-07-01T04:03:41Z Indexed on 2013/07/01 4:21 UTC
Read the original article Hit count: 122

Filed under:
|

I have an Activity with a WeView that load an url, and I want to display a little waiting dialog during the load of the site, so I have tried this:

private ProgressDialog dialog = new ProgressDialog(MyNameActivity.this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);
        setContentView(R.layout.web_view_activity);

        WebView wv;
        wv = (WebView) findViewById(R.id.areaWebSolver);
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
            @Override
        public void onPageFinished(WebView view, String url) {                  
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }

        });
        dialog.setMessage("Loading..Please wait.");
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        wv.loadUrl(url);

        WebSettings webSettings = wv.getSettings();
        webSettings.setJavaScriptEnabled(true);

    }

Unfortunately doesn't works and the app crashes with a source not found... If I try to remove the Progress dialog code the activity works. What's wrong? How could I fix this?

© Stack Overflow or respective owner

Related posts about android

Related posts about webview