FullScreen crashing in WebView Video on some Android devices When using application context

As we all know, Webview can cause a memory leak in some cases. Therefore, I use the application context to create a web view, such as new WebView(getApplicationContext()) .

I need to do a fullscreen video view so that I redefine WebChromeClient#onShowCustomView() . After testing several devices, one of them caused crashes each time you click on the full-screen icon.

This is the trace:

 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:697) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:345) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224) at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149) at android.view.Window$LocalWindowManager.addView(Window.java:554) at android.widget.MediaController.show(MediaController.java:338) at android.webkit.HTML5VideoFullScreen.showControllerInFullScreen(HTML5VideoFullScreen.java:387) at android.webkit.HTML5VideoViewProxy$VideoPlayer.end(HTML5VideoViewProxy.java:310) at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:450) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4898) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) at dalvik.system.NativeStart.main(Native Method)` 

This works well when I used activity to create a webview.

So what's the difference with this Android device?
Is the core ( Chrome Webkit ) or the difference in the implementation of the version for Android? How can i fix this?

+3
source share
1 answer

If you create a new action and hide the action bar and add the WebView tag to your xml business, you will no longer run into this problem. And you can get full screen mode. But this is a bug in the android web browser, and Google has thrown the update to solve this problem.

0
source

Source: https://habr.com/ru/post/1200598/


All Articles