Log DEV_ACTION_COMPLETED seems to del

2019-04-28 20:57发布

问题:

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.