2

I have a webview that I'm creating in an Activity which is a child of an Activity Group. The issue I'm having is that when I load an external weblink, the webview crashes when I click a link that would bring up a dialog:

03-28 12:06:24.189: E/AndroidRuntime(629): 
android.view.WindowManager$BadTokenException:
Unable to add window -- token 
android.app.LocalActivityManager$LocalActivityRecord@44ef7060 is not valid;
is your activity running?

So basically the issue I'm having, I think, is very similar to this question:

Webview crashes on select box or any Dialog

And the answer probably will work for me, the difference is that I'm declaring my webview from an xml file:

this.mainWebView = (WebView) findViewById(R.id.proxSearchWebView);

I'm still very new to Android Dev, so I'm assuming that declaring my webview in this way is setting the context to "this" , is there a way to set the context to getParent() while still using XML?

So basically, is there a way to make this work while still defining the webview through XML or do I have to programmatically create the webview entirely?

Community
  • 1
  • 1
Jag
  • 1,744
  • 2
  • 11
  • 11

1 Answers1

2

android.view.WindowManager$BadTokenException: is basically due to context problem. Probably you are using the context of the current activity for create your dialog. You should use the parent activity context for create a dialog when you are using the Activity group.

You can get parent activity context by calling getParent().

Here is the link that you can refer for the same issue

Community
  • 1
  • 1
Dharmendra
  • 33,296
  • 22
  • 86
  • 129
  • 1
    Even after getParent() for WebView inside TabHost, issue is there in >4.0 devices, yes its working fine for <2.3 devices. I will do research and post solution if i found any. – Paresh Mayani Mar 20 '13 at 13:25