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
Asked
Active
Viewed 61 times
1 Answers
0
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);
}
}

Ramy Ibrahim
- 656
- 4
- 19
-
Thanks for your suggestion, but the thing is I have 3 different activities useing webview to load a url, So i maked a separate general file for writing all webview function and using that file object to load url and get scrap data. So i want to generalize onPageFinished function, to call different functions from the calling activity. – irshad ahmed Oct 08 '20 at 04:29