Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7432387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:26:57+00:00 2026-05-29T09:26:57+00:00

So I followed a post on avoiding WebView memory leaks, which suggests to use

  • 0

So I followed a post on avoiding WebView memory leaks, which suggests to use a webview container and then programmatically add/remove the webview from the container in activity codes:
Memory leak in WebView

However, I hit the following crash when clicking on an html element which prompts 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 -- token null is not for an application
 android.view.ViewRoot.setView(ViewRoot.java:561)
 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
 android.app.Dialog.show(Dialog.java:265)
 android.webkit.WebView$InvokeListBox.run(WebView.java:9170)
 android.os.Handler.handleCallback(Handler.java:587)
 android.os.Handler.dispatchMessage(Handler.java:92)
 android.os.Looper.loop(Looper.java:150)
 android.app.ActivityThread.main(ActivityThread.java:4263)
 java.lang.reflect.Method.invokeNative(Native Method)
 java.lang.reflect.Method.invoke(Method.java:507)
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 dalvik.system.NativeStart.main(Native Method)

I have the following in my layout:

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 set a WebViewClient.

I have verified that mWebView.getWindowToken() does return a non-null value.

Any ideas as to why this issue might be happening?

Edit:
I’ve done some more experimenting and looking around, but still haven’t solved this issue. Everything functions fine if I put the webview directly in the layout itself. But I don’t want to do that because I want to be able to dynamically swap webviews.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:26:57+00:00Added an answer on May 29, 2026 at 9:26 am

    When you create the WebView you are currently using the context of the application.
    You should be using the context of the Activity. To solve the problem, replace getApplicationContext() with this when you create the WebView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed Spring Security Plugin( from here ). I followed the blog post very
I have followed a link http://lukesampson.com/post/315838839/cas-on-windows-localhost-setup-in-5-mins , then the cas server works correctly, the
I read this post: What is the easiest-to-use web "rich text editor" and followed
I followed a blog post here to use a custom validator to validate a
I downloaded AutoScale from http://blog.maartenballiauw.be/post/2011/03/21/Windows-Azure-and-scaling-how-(NET).aspx and followed the instructions there. I added it as
I have followed the suggestions from this post to try and get Distinct() working
I followed the wiki post to add username as another authentication method for Devise..
I want to use TempData to store messages between Post and followed redirect but
I followed an example from the following url that shows how to use the
I have followed the Accepted Answer's instructions from this post as regards creating a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.