0

In my app I use webview to display webpages defined by user. IF webpage contains video the video doesn't stop after back is pressed and activity is stopped. I've solve this issue in older implementation (android.webkit.WebView) but now I'm facing this issue again in kitkat which uses webview from chromium package. Here is the code I'm using in older versions. I'm looking to do the same in >=4.4 android versions.

    if(webView!=null){
                        try {
                            Class.forName("android.webkit.WebView")
                                    .getMethod("onPause", (Class[]) null)
                                                .invoke(webView, (Object[]) null);

                        } catch(ClassNotFoundException cnfe) {
                        } catch(NoSuchMethodException nsme) {
                        } catch(InvocationTargetException ite) {
                        } catch (IllegalAccessException iae) {
                        }
 }
Picmann
  • 45
  • 2
  • 12

2 Answers2

1

Hmmm... how about you try loading a bogus url, forcing the webview to dump the current webpage:

myWebView.loadUrl("about:blank");
Adrian Sicaru
  • 1,382
  • 1
  • 11
  • 20
  • Yes it seems to be that easy. On older version I remember this didn't worked as wanted, but it's ok for me at this moment. – Picmann Oct 21 '14 at 09:29
0

you have to stop webview onpause

@Override
public void onPause() {
    // TODO Auto-generated method stub

    try {
        webView.loadUrl("about:blank");

    } catch (Exception e) {
    }
    super.onPause();
}
raj
  • 2,088
  • 14
  • 23