So, I followed the WebView memory leak exception message, which suggests using the webview container, and then programmatically add / remove the web view from the container in activity codes: Memory leak in WebView
However, I hit the following crash when I click on an html element that asks for a list of options to select (e.g. date / month drop-down menu)
W/dalvikvm(17767): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0) W/WindowManager(129): Attempted to add window with non-application token WindowToken{4094b730 token=null}. Aborting. FATAL EXCEPTION: main android.view.WindowManager$BadTokenException: Unable to add window
My layout has the following:
FrameLayout android:id="@+id/webview_container" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/titlebar"> /FrameLayout>
I have the following in onCreate ():
mWebViewContainer = (FrameLayout)findViewById(R.id.webview_container); mWebView = new WebView(getApplicationContext()); mWebViewContainer.addView(mWebView); mWebView.setWebChromeClient(new WebChromeClient());
I also install WebViewClient.
I checked that mWebView.getWindowToken () returns a non-zero value.
Any ideas as to why this issue could happen?
Edit: I experimented a bit more and looked around, but still haven't solved this problem. Everything works fine if I put the webview directly into the layout itself. But I do not want to do this, because I want to be able to dynamically change web views.
android webview
Zack foster
source share