1

I use WebView for JS-scripts executing. But sometimes this script can hang. I want to set Timer before script executing and kill this script after specified delay (if this script working too long time). But how to kill script? I've try to use WebView.stopLoading(), but it doesn't help.

This is my code:

WebView webView;

void runScript() {

    webView = new WebView(context);

    TimerTask timerTask=new TimerTask() {
                @Override
                public void run() {
                    webView.stopLoading();
                }
            };
    Timer timer=new Timer();
    timer.schedule(timerTask, 5000);

    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    ...
    webView.setWebChromeClient(new ChromeClient(new JSHandler(context)));
    webView.loadData("<script language=\"JavaScript\">\n" + jsCode + "\n</script>", "text/html", "utf-8");
}
4

1 回答 1

0

我找到了解决方案: WebView.destroy();

于 2012-09-20T10:38:34.923 回答