views:

40

answers:

1

Hello all, I am quite new to Android yet, and I have an application that has a webview on it.

I need to know when the webview finishes loading a page that has a random number of redirects (sometimes to the same page, and the order of the redirects also change), so I can remove the Splash Screen only when there is a fully loaded page.

On the webviewclient the onPageStarted and onPageFinished functions are called once per each redirect, as is the onNewPicture (even though the screen is always blank during the redirects). So I can't be sure when it's called the last time (page actually loaded).

I also tried using the onLoadResource to count the number of resources loaded (dangerous and unreliable approach, but I am getting desperate here), but this also failed, since after the page is cached, it is called only one or two times.

That is one big puzzle I am unable to solve using what I know so far, can anyone please help me?

Thanks a lot in advance.

+1  A: 

Off the cuff, it sounds like you have a Web site that needs to be rewritten... :-)

Here are two possibilities I can think of:

  1. If you get an onPageFinished() and no onPageStarted() after such-and-so period of time, assume the redirects are done.
  2. If these redirects are all HTTP redirects (3xx response status codes), you could use HttpClient to navigate the redirects until you get the final URL, then give that URL to WebView to display.
CommonsWare
+1 for the rewrite suggestion
Falmarri
I agree, I just wish I had control over that website...
By the way, I tried your sugestion, I am now counting the time between each start and finish, and ignoring the very fast ones (redirects) this way the worse that can happen is to remove the splash screen ahead of time on very very very fast 3g connections... I think that is going to be ok...Thanks