Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView Window Leaked

I have encountered this problem in my bigger project using WebView, but when I couldn't find anything wrong with my code, I made a simple project that contains only two things:

MainActivity with this particular code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView webView = (WebView) findViewById(R.id.webView);
    Uri uri = Uri.parse("android.resource://whatever");
    webView.loadUrl(uri.toString());
}

activity_main.xml contains only a layout and a Webview. Nothing else.

Now, the webview displays a message that it can't display the website and it's ok. It doesn't matter if it displays it or not. And here's the deal: when I select a text and the pop-up shows (with copy | paste), and then I go back clicking the Back button(resulting in closing the activity), I get this following exception (no crash):

E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7fb64bfadb20
E/WindowManager: android.view.WindowLeaked: Activity com.example.***.richwebeditor.MainActivity has leaked window android.widget.PopupWindow$PopupDecorView{ffd5bff V.E...... ........ 0,0-116,58} that was originally added here
      at android.view.ViewRootImpl.<init>(ViewRootImpl.java:368)
      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
      at android.widget.PopupWindow.invokePopup(PopupWindow.java:1258)
      at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1032)
      at android.widget.PopupWindow.showAtLocation(PopupWindow.java:995)
      at org.chromium.content.browser.input.PopupTouchHandleDrawable.show(PopupTouchHandleDrawable.java:354)
      at org.chromium.android_webview.AwContents.nativeOnDraw(Native Method)
      at org.chromium.android_webview.AwContents.access$4500(AwContents.java:92)
      at org.chromium.android_webview.AwContents$AwViewMethodsImpl.onDraw(AwContents.java:2731)
      at org.chromium.android_webview.AwContents.onDraw(AwContents.java:1191)
      at com.android.webview.chromium.WebViewChromium.onDraw(WebViewChromium.java:1713)
      at android.webkit.WebView.onDraw(WebView.java:2486)
      at android.view.View.draw(View.java:16178)
      at android.view.View.updateDisplayListIfDirty(View.java:15174)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
      at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615)
      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
      at android.view.Choreographer.doCallbacks(Choreographer.java:670)
      at android.view.Choreographer.doFrame(Choreographer.java:606)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7fb63de30880
E/WindowManager: android.view.WindowLeaked: Activity com.example.***.richwebeditor.MainActivity has leaked window android.widget.PopupWindow$PopupDecorView{7220dcc V.E...... ........ 0,0-116,58} that was originally added here
      at android.view.ViewRootImpl.<init>(ViewRootImpl.java:368)
      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
      at android.widget.PopupWindow.invokePopup(PopupWindow.java:1258)
      at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1032)
      at android.widget.PopupWindow.showAtLocation(PopupWindow.java:995)
      at org.chromium.content.browser.input.PopupTouchHandleDrawable.show(PopupTouchHandleDrawable.java:354)
      at org.chromium.android_webview.AwContents.nativeOnDraw(Native Method)
      at org.chromium.android_webview.AwContents.access$4500(AwContents.java:92)
      at org.chromium.android_webview.AwContents$AwViewMethodsImpl.onDraw(AwContents.java:2731)
      at org.chromium.android_webview.AwContents.onDraw(AwContents.java:1191)
      at com.android.webview.chromium.WebViewChromium.onDraw(WebViewChromium.java:1713)
      at android.webkit.WebView.onDraw(WebView.java:2486)
      at android.view.View.draw(View.java:16178)
      at android.view.View.updateDisplayListIfDirty(View.java:15174)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
      at android.view.View.updateDisplayListIfDirty(View.java:15134)
      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
      at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615)
      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
      at android.view.Choreographer.doCallbacks(Choreographer.java:670)
      at android.view.Choreographer.doFrame(Choreographer.java:606)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7fb63de30340

I tested it on three different Samsung Galaxy devices (Android 6.1), an emulator (7.0) and an old HTC phone (5.0). I got exceptions in every case.

Has anyone encountered this problem? Is it a bug with Android webview? Is there a solution?

EDIT: Screens for reference about what pop-up I'm talking about:

Imgur1

Imgur2

like image 899
dabu Avatar asked Nov 09 '22 04:11

dabu


1 Answers

It looks like a good workaround for this issue is to call

webView.destroy()

when finishing the activity. I believe there is a better solution for this problem and will leave this thread unresolved for a while so maybe someone who experienced it will share the proper way of handling it.

like image 60
dabu Avatar answered Nov 28 '22 01:11

dabu