Amar Kalabić
Amar Kalabić

Reputation: 898

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

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?

Upvotes: 3

Views: 1322

Answers (2)

BDRSuite
BDRSuite

Reputation: 1612

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.

Upvotes: 0

Alejandro Zurcher
Alejandro Zurcher

Reputation: 459

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
    }
}
});

Upvotes: 5

Related Questions