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

半腔热情 提交于 2019-12-07 03:29:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17995739/log-gate-mdev-action-completed-gate-m-seems-to-delay-execution-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!