androidwebviewandroid-4.4-kitkatwebviewchromium

webview keeps playing after activity is paused


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) {
                        }
 }

Solution

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

    myWebView.loadUrl("about:blank");