Reputation: 2153
I am having this strange issue on Nexus Devices like Nexus 4 , Galaxy Nexus and Nexus 7. I have a browser like app with multiple tabs each having a Webview.
If I open a site like Google.com in multiple tabs(2 or more), the webviews do not take clicks. Also websites load up pretty slow. Following are my webview settings
private void doWebSettings(WebView webview) {
webview.setScrollbarFadingEnabled(true);
webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
// enable smooth transition for better performance during panning or
// zooming
if (currentSdk >= OS_3_0) {
webSettings.setEnableSmoothTransition(true);
}
// For Zooming out completely
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccess(true);
try {
webSettings.setAllowContentAccess(false);
} catch (NoSuchMethodError e) {
e.printStackTrace();
}
String databasePath = this.getApplicationContext()
.getDir("database", Context.MODE_PRIVATE).getPath();
webSettings.setDatabasePath(databasePath);
webSettings.setGeolocationDatabasePath(this.getApplicationContext()
.getDir("geolocation", 0).getPath());
webSettings.setRenderPriority(RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setDatabaseEnabled(true);
// Dont focus on any webview item by default
webSettings.setNeedInitialFocus(false);
if (!isTablet) {
webSettings
.setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
}
}
If i set Javascript enabled to 'False', all the webviews work smoothly. This issue is prominently observed on all nexus devices, sometimes the webviews don't take clicks for few minutes. This behavior is making the app unusable. I am presuming that some Javascript is consuming UI thread for the Webview and that's the reason its getting stuck. I get a warning in Eclipse for setJavascriptEnabled(true); as "Using setJavaScriptEnabled can introduce XSS vulnerabilities into you application, review carefully." i searched for this warning on the internet but dint find any relevant answer. Also i have checked some posts related to people facing issue with Webview performance on Jellybean. What am i missing here ?
Upvotes: 2
Views: 1131
Reputation: 2153
Found the culprit.
webview.freeMemory()
I was calling this function to release memory on every tab change. Commenting this code fixed the issue. I am not sure for the reason behind this but the Webview goes into some processing state for long time and does not take UI clicks.
Upvotes: 0