Check if certain url is finished loading, then open another one in WebView

1.3k views Asked by At

I want to check if certain URL is finished loading, and then load another URL and if that new url is finished loading do something, how?

I know how to check if certain URL is finished loading like this:

webView.setWebViewClient(new WebViewClient() {

    public void onPageFinished(WebView view, String url) {
        // do stuff here
    }
    });

But what I want is:

 if url1 finished loading:
    load url2
    if url2 finished loading:
       //do some stuff here

How can I do this?

2

There are 2 answers

0
Alejandro Zurcher On BEST ANSWER

The url String parameter of onPageFinished always returns the actual URL loaded in the WebView.

You should do something like this:

webView.setWebViewClient(new WebViewClient() {

String urlA = "http://facebook.com";
String urlB = "http://facebook.com/friends";

public void onPageFinished(WebView view, String url) {
    if(url.equals(urlA)){
        //Do stuff if actual page url is urlA        
    }else if(url.equals(urlB)){
        //Do stuff is actual page url is urlB
    }
}
});
0
BDRSuite On

You need to load urls consecutively after the prior one loads completely.

the onProgressChanged() can be used. Please refer this SO answer, it is clear.