简体   繁体   中英

How to stop java code execution util a link in webView is loaded completely in android studio

I am trying to make a web scraping application in android studio, in which on extracted data I want to perform some action using java code. Problem is that webview works asynchronously that is, it will go on executing remaining line of same method along with loading website in webview. But my code after webview.url call needs data which is only available when site is completely loaded, so I want java to wait, for site to completely load then execute remaining line of code. Any suggestion is appreciated

webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyWebViewClient());

progress = (ProgressBar) findViewById(R.id.progressBar);
progress.setVisibility(View.GONE);

private class MyWebViewClient extends WebViewClient {   
 @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

     @Override
    public void onPageFinished(WebView view, String url) {
         progress.setVisibility(View.GONE);             
        super.onPageFinished(view, url);
 // Here webview for finished loading
    }

     @Override
     public void onPageStarted(WebView view, String url, 
 Bitmap favicon) {
          progress.setVisibility(View.VISIBLE);          
        super.onPageStarted(view, url, favicon);
    }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM