问题描述
我有我创建一个活动是活动组的子网页视图。我遇到的问题是,当我加载外部网站链接,当我点击一个链接,会弹出一个对话框中的WebView崩溃:
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在选择框或任何对话
和答案可能会为我工作,所不同的是,我从一个XML文件中声明我的WebView:
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);
我还是很新的Android开发人员,所以我假设我宣布的WebView以这种方式设置的背景下本,是有办法来设置上下文的getParent(),同时仍然使用XML ?
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?
因此,基本上,是有办法,使这项工作,同时还定义通过XML的web视图或我以编程方式完全建立的WebView?
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?
推荐答案
android.view.WindowManager $ BadTokenException:
基本上是由于环境问题。也许你正在使用创建对话框当前活动的情况下。您应该使用父活动上下文创建当您使用活动组的对话框。
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.
您可以通过调用获取父活动的上下文的getParent()
。
You can get parent activity context by calling getParent()
.
下面是,你可以参考对同一问题
Here is the link that you can refer for the same issue
这篇关于在网页视图活动组崩溃的对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!