Log <GATE-M>DEV_ACTION_COMPLETED</GATE-M> seems to delay execution on Android
Asked Answered
S

1

6

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?

Shaker answered 1/8, 2013 at 13:41 Comment(2)
Try adding webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); before webSettings.setJavaScriptEnabled(true);. Also Look at this: #5820737Chilpancingo
Will give it a go in a couple of hours...Shaker
S
5

We have managed to sketch up a solution for this crappy issue... no matter what I've tried I could not find a Java solution to this issue, but we did find an HTML + JavaScript solution:

Instead of waiting for the onPageFinish of the java, we inject a java script to listen to the window.onLoad event...

and there we inject our actual JavaScript... works like a charm...

For more details.

Shaker answered 19/8, 2013 at 13:37 Comment(2)
Your solution works well and I +1'ed your solution. But I would be a happier camper if I could figure out the root cause of the problem since it happens on select url. For example, with the url as google.com, onPageFinished always triggers immediately. With another url such as linkedIn's auth url, onPageFinished does not trigger on the first load after clearing the app's cache through settings. And observing from overriding the methods of webviewclient and web chromeclient, there are no redirects or errors happening on that page.Faizabad
I think it has to do with content loading... if you would build a simple webview app, and print out all the callbacks, you would notice, that also shouldOverride...url() method is not called for each loading, it depends if the request is get or post, it depends if these are AJAX calls, I've found there are many reasons for this, and also that the ChromeClient reports the same as the WebViewClient.Shaker

© 2022 - 2024 — McMap. All rights reserved.