How to detect the web page was load finished??

384 views
Skip to first unread message

Rick

unread,
Jan 31, 2008, 9:51:46 AM1/31/08
to Android Developers
Dear all,
I try to load some web page step by step, and detect the current
page was load finished before load next page.
Here is my code :

//default page is "http://www.microsoft.com/en/us/
default.aspx"

wv.loadUrl("http://www.yahoo.com");
showAlert("Current Page 1 : ",wv.getUrl(), "ok", false);
while(wv.getProgress()<100)
{
}
wv.loadUrl("http://www.google.com");
showAlert("Current Page 2 : ",wv.getUrl(), "ok", false);
while(wv.getProgress()<100)
{
}

But, the alert message shows
"Current Page 1 : http://www.microsoft.com/en/us/default.aspx"
"Current Page 2 : http://www.microsoft.com/en/us/default.aspx"
and wv.getProgress() = 100
It seems asynchronous.
Any way to solve the problem??

muntzen

unread,
Jan 31, 2008, 3:45:07 PM1/31/08
to Android Developers
Use a BrowserCallback:
http://code.google.com/android/reference/android/webkit/BrowserCallback.html

Using your code as an example:

wv.setBrowserCallback(new WebViewCallback());
...

// create an inner class to handle the callbacks from the webview
/* package-scope */ class WebViewCallback extends
BrowserCallbackAdapter
{

// when the resource loads add a javascript interface
public void setProgress(int progress)
{
if (progress == 100)
.....

muntzen

unread,
Jan 31, 2008, 3:46:01 PM1/31/08
to Android Developers
haha, ignore that javascript interface comment. that was some test
code. :)

On Jan 31, 3:45 pm, muntzen <ericmu...@gmail.com> wrote:
> Use a BrowserCallback:http://code.google.com/android/reference/android/webkit/BrowserCallba...
Reply all
Reply to author
Forward
0 new messages