Search code examples
androidwebviewwebviewclient

When does onNewPicture() get called?


The documentation for onNewPicture() only says:

Notify the listener that the picture has changed

My question is: When does the picture change?

I noticed that some web pages generate dozens of onNewPicture(), so obviously the "picture" changes many times in the course of rendering the page on a WebView.

What makes a WebView picture change?

I haven't seen any page page that generates less than 2 onNewPicture() calls, so is onNewPicture() guaranteed to be called more than once, for any given HTML page?


Solution

  • PictureListener.onNewPicture() is called whenever the already loaded page finished rendering (or re-rendering in case certain events make the WebKit engine re-calculate page layout). It really depends on the page being loaded:

    A simple text-only page will be rendered only once. Other pages (especially Javascript-heavy ones) can be called numerous times after the page finished loading.

    Tip by @littleFluffyKitty found in another posting: Many webpages today will cause it to get called fairly often as you move around the page so make sure whatever happens in the onNewPicture() method is quick.