完全停止在Android的WebView [英] Completely stop an android webview

查看:494
本文介绍了完全停止在Android的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个机器人的WebView,并允许用户使用的window.onload回调里面自己的JavaScript(其完全隔离,​​我个人不认为存在安全隐患)。如果输入类似以下出现该问题。

I have an android webview and allow the user to use their own javascript inside a window.onload callback (its completely isolated and I personally don't see a security risk). The problem occurs if something like the following is entered

while(true){
}

在Java这一边,我打开一个定时器后约5秒钟的JavaScript仍在我试图阻止web视图。我曾尝试各种事情:

In the java side of things, I start a timer and after about 5 seconds if JavaScript is still going I try to stop the webview. I have tried various things:

webView.stopLoading();
webView.loadData("", "text/html", null);
webView.freeMemory();
webView.pauseTimers();
webView.destroy();
Class.forName("android.webkit.WebView").getMethod("onPause", (Class[]) null).invoke(webView, (Object[]) null);

每一个开始有点更加绝望:)。没有什么作品和一个线程继续进行,直到我退出该应用使用处理器。有谁知道我怎么能正确地阻止它?

each one getting a little more desperate :). Nothing works and a thread continues to use up the processor until I quit the app. Does anyone know how I can stop it correctly?

任何帮助很多AP preciated,
伊恩

Any help is much appreciated, Ian

推荐答案

你试过破坏的WebView前禁用了JavaScript?这似乎是JavaScript的跨preTER是活得比你的WebView,但也许如果你告诉它停止执行,那么你会解决你的问题。我想尝试在你的计时方法的顶部使用这样的:

Have you tried disabling JavaScript before destroying the WebView? It seems like the JavaScript interpreter is outliving your WebView, but perhaps if you tell it to stop executing, then you will solve your problem. I'd try using this at the top of your timed method:

webView.getSettings().setJavaScriptEnabled(false);

这篇关于完全停止在Android的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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