我有在 webview 上运行 jquery mobile 的网站。当活动开始时,一切正常,但在活动暂停 30 分钟或更长时间后,我返回 web 视图,它不再工作了。看起来 JavaScript 停止响应。
我正在使用 web.load(url) 方法加载网页。
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
private void initUI(View view)
{
logger.info("initUI() - Initilazing Fragment UI");
webViewPlaceholder = ((FrameLayout)view.findViewById(R.id.webViewPlaceholder));
if (webView == null)
{
logger.info("initUI() - Creating WebView");
webView = new WebView(this.getActivity());
FrameLayout.LayoutParams layoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT);
webView.setLayoutParams(layoutParameters);
webView.addJavascriptInterface(new JavascriptUtils(this.getActivity()), "Android");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
if (Build.VERSION.SDK_INT >= 11){
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webView.setHorizontalScrollBarEnabled(false);
webView.setWebViewClient(SeeWhatYouLikeWebClientFactory.getWebClient(this));
webView.setWebChromeClient(new SWYLWebChromeClient());
}
// Attach the WebView to its placeholder
webViewPlaceholder.addView(webView);
}
谢谢