1

I have a WebView inside a RecyclerView

I configured the WebViewClient to run onPuase() when page finished loading.

The problem is that some websites (like IMDB) are not viewed, unless I scroll the page down/up, or if the page in stored in cache.

Not working code:

getWebview().setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            view.onPause();
        }  
    });

If I delay the onPause, it works (delay time differs between different devices)

    getWebview().setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(final WebView view, String url) {
            super.onPageFinished(view, url);
                    getWebview().postDelayed(new Runnable() {

                           @Override
                          public void run() {
                                getWebview().onPause();
                          }
                   }, 5000);
        }  
    });

I also tried getWebview().postInvalidateDelayed() and getWebview().requestLayout().

Is there anyway to force the webview to display the loaded content, or simulate whatever happens when I scroll the page?

  • I use Lollipop with Android System WebView 43.0.2357.121
Jude
  • 545
  • 3
  • 20
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130

1 Answers1

1

If you try to debug or put some logs in onPagefinshed() method, you will come to know that Webview's onPauuse() will call 2-3 times before site the loads completely in case of URL redirecting.

Bunny
  • 576
  • 4
  • 19
  • Thanks. I solved it using the following post: http://stackoverflow.com/questions/18282892/android-webview-onpagefinished-called-twice – Asaf Pinhassi Jul 15 '15 at 10:41