Webview在选择框或任何对话框上崩溃 [英] Webview crashes on select box or any Dialog

查看:313
本文介绍了Webview在选择框或任何对话框上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中点击列表中的项目显示具有javascript注入的Webview。我需要保存Webview对象,以便当用户再次按下相同的项目时,显示现有的Webview而不是重新加载它并注入我可以将webview对象保存在应用程序类中的webview的Arraylist中。



我检查该项目是否已经存在于Arraylist中,如果它存在取相应对象,并将对象设置为活动的内容,如下所示。

  temp_WebView = new WebView(this); 
temp_WebView =(WebView)application.getWebview(j);
ViewGroup parent =(ViewGroup)application.getWebview(j).getParent();
parent.removeView(application.getWebview(j));
setContentView(temp_WebView);

这工作正常,但是当点击网络视图中任何一个填充对话框的选择框时,它会崩溃,出现以下错误:


WARN / WindowManager(60):尝试添加具有未知令牌的应用程序窗口HistoryRecord {4506d1e8 tabviewapp.com/.Webresults}。中止。

DEBUG / AndroidRuntime(500):关闭VM

WARN / dalvikvm(500):threadid = 1:线程退出与未捕获的异常(组= 0x4001d800)
ERROR / AndroidRuntime(500):FATAL EXCEPTION:main
ERROR / AndroidRuntime(500):android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.os.BinderProxy@45034510无效;你的活动是否运行?
ERROR / AndroidRuntime(500):在android.view.ViewRoot.setView(ViewRoot.java:505)
错误/ AndroidRuntime(500):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java: 177)

错误/ AndroidRuntime(500):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

错误/ AndroidRuntime(500):在android。 view.Window $ LocalWindowManager.addView(Window.java:424)

错误/ AndroidRuntime(500):在android.app.Dialog.show(Dialog.java:241)

ERROR / AndroidRuntime(500):在android.webkit.WebView $ InvokeListBox.run(WebView.java:7095)

错误/ AndroidRuntime(500):在android.os.Handler.handleCallback( Handler.java:587)

错误/ AndroidRuntime(500):在android.os.Handler.dispatchMessage(Handler.java:92)

错误/ AndroidRuntime(500) :在android.os.Looper.loop(Looper.java:123)

错误/ AndroidRuntime(500):在android.app.ActivityThread.main(ActivityThread.java:4627)

ERROR / AndroidRuntime(500):at java.lang.reflect.Method.invokeNative(Native Method)

ERROR / AndroidRuntime(500):at java.lang.reflect.Method.invoke(Method。 java:521)

错误/ AndroidRuntime(500):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)

错误/ AndroidRuntime(500):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

ERROR / AndroidRuntime(500):at dalvik.system.NativeStart.main(Native Method )

WARN / ActivityManager(60):强制整理活动tabviewapp.com/.Webresults

我认为问题是webview的上下文,但不能弄清楚如何将现有对象或传递上下文的上下文设置为在Webview中生成的对话框。



提前感谢

解决方案

我也有类似的问题。在我的情况下,webview是在一个ActivityGroup。 ActivityGroups和对话框不能开箱即用。在我的情况下,我不得不使用它作为上下文,而是使用getParent()。

  temp_WebView = new WebView(getParent() ); 


I have an application where clicking on an item in a list shows webview with javascript injected.I need to save the webview object so that when the user presses the same item again the existing webview is shown instead of reloading it and injecting the javascript again.I am able to save the webview object in Arraylist of webview inside the application class.

I check whether the item already exists in the Arraylist and if it do exists take the corresponding object and set the object as the content of the activity as shown below.

     temp_WebView=new WebView(this);                
     temp_WebView=(WebView)application.getWebview(j);
     ViewGroup parent = (ViewGroup) application.getWebview(j).getParent();
     parent.removeView(application.getWebview(j));  
     setContentView(temp_WebView);

This works fine but when clicking on any of the select box inside the webview where a dialog is populated it gets crashed  with the following error,


WARN/WindowManager(60): Attempted to add application window with unknown token HistoryRecord{4506d1e8 tabviewapp.com/.Webresults}.  Aborting.

 DEBUG/AndroidRuntime(500): Shutting down VM

 WARN/dalvikvm(500): threadid=1: thread exiting with uncaught exception (group=0x4001d800)    
 ERROR/AndroidRuntime(500): FATAL EXCEPTION: main    
 ERROR/AndroidRuntime(500): android.view.WindowManager$BadTokenException: Unable to  add window -- token android.os.BinderProxy@45034510 is not valid; is your activity running?
 ERROR/AndroidRuntime(500): at android.view.ViewRoot.setView(ViewRoot.java:505)
 ERROR/AndroidRuntime(500): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)

 ERROR/AndroidRuntime(500):  at      android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

 ERROR/AndroidRuntime(500):     at android.view.Window$LocalWindowManager.addView(Window.java:424)

 ERROR/AndroidRuntime(500):     at android.app.Dialog.show(Dialog.java:241)

 ERROR/AndroidRuntime(500):     at android.webkit.WebView$InvokeListBox.run(WebView.java:7095)

 ERROR/AndroidRuntime(500):     at android.os.Handler.handleCallback(Handler.java:587)

 ERROR/AndroidRuntime(500):     at android.os.Handler.dispatchMessage(Handler.java:92)

 ERROR/AndroidRuntime(500):     at android.os.Looper.loop(Looper.java:123)

 ERROR/AndroidRuntime(500):     at android.app.ActivityThread.main(ActivityThread.java:4627)

 ERROR/AndroidRuntime(500):     at java.lang.reflect.Method.invokeNative(Native Method)

 ERROR/AndroidRuntime(500):     at java.lang.reflect.Method.invoke(Method.java:521)

 ERROR/AndroidRuntime(500):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

 ERROR/AndroidRuntime(500):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

 ERROR/AndroidRuntime(500):     at dalvik.system.NativeStart.main(Native Method)

 WARN/ActivityManager(60):   Force finishing activity tabviewapp.com/.Webresults

I think the problem is with the context of the webview but not able to figure out how to set the context for the existing object or pass context to dialog generated inside the webview.

Thanks in advance.

解决方案

I had a similar problem. In my case the webview was in an ActivityGroup. ActivityGroups and dialogs don't work out of the box. In my case I had to not use this as context, instead use getParent().

temp_WebView=new WebView(getParent());

这篇关于Webview在选择框或任何对话框上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆