I've recently noticed that my app has the occasional LAG. and by LAG I mean it can take up to 40 seconds, depends if I use Wifi or mobile data...
I load a page url, and then load js for execution:
webView = (WebView) view.findViewById(R.id.WebView);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
logDebug("Loading URL: " + url);
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return WrappingClass.this.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
logInfo("loading JavaScript to webview.");
webView.loadUrl("full-js-here");
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
logError("error code:" + errorCode);
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webView.requestFocus(View.FOCUS_DOWN);
webView.loadUrl("url");
After calling the load url, the page is displayed in the web view, the UI is responsive, I can click on buttons, go back, and navigate the application...
BUT
The script I'm trying to run is not executed, not until the DEV_ACTION_COMPLETED is printed to the log, then everything goes back to normal, and the onPageFinished is called and runs the script instantaneously. problem is this can take up to 40 seconds.
== UPDATE ==
It seems that the delay is growing to some point, and after that the delay is shorten to nothing and grows again... its like a sequence: 0,1,2,4,8,16,32... and then starts from 0.
Could it be because I'm creating new activities with webview, in a too short of a time?
Any thoughts?
webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient());
beforewebSettings.setJavaScriptEnabled(true);
. Also Look at this: #5820737 – Chilpancingo