Jquery webview应用程序超级低,如何加快速度?

时间:2014-02-25 17:46:23

标签: android jquery performance android-webview android-manifest

我在我的android webview中使用JQuery,而且应用程序非常慢,需要大约10-15秒才能浏览。有没有办法可以加快速度?我已经尝试了书中的每一个帖子和几乎每一个技巧,有什么我想念的吗?是的,我已经在清单中添加了hardwareaccelerated,但仍然没有运气!

public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
       // getWindow().requestFeature(Window.FEATURE_PROGRESS);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
        progress = (ProgressBar) findViewById(R.id.ProgressBar);
        progress.setVisibility(View.VISIBLE);
         webview = (WebView)findViewById(R.id.webview);
        webview.setInitialScale(1);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setLoadWithOverviewMode(true);
        webview.getSettings().setUseWideViewPort(true);
      //  webview.setWebViewClient(new MyCustomWebViewClient());
        if (Build.VERSION.SDK_INT >= 11){
            webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }
        webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        webview.setScrollbarFadingEnabled(false);
       webview.getSettings().setRenderPriority(RenderPriority.HIGH);
        webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
       // webview.getSettings().setBlockNetworkLoads(true);
        webview.getSettings().setBuiltInZoomControls(true); 
        webview.loadUrl("file:///android_asset/index.html");
        webview.getSettings().setDomStorageEnabled(true);
        webview.getSettings().setDatabaseEnabled(true);
        webview.getSettings().setAppCacheEnabled(true);
        //http://www.inpixelitrust.fr/demos/restaurant_picker/
        //file:///android_asset/index.html
        webview.getSettings().setSupportZoom(false);

       /* webview.setWebChromeClient(new WebChromeClient()
        {
         public void onProgressChanged(WebView view, int progress)
         {
           // update the progressBar
           MainActivity.this.setProgress(progress * 100);
         }
        });*/
        if (!isTaskRoot()) {
            final Intent intent = getIntent();
            final String intentAction = intent.getAction();
            if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
                finish();
                return;
            }
        }

    }

    private class MyCustomWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            progress.setVisibility(View.VISIBLE);
          }
          public void onPageFinished(WebView view, String url) {
            progress.setVisibility(View.GONE);
            synchronized (SPLASH_LOCK) {
                SPLASH_LOCK.notifyAll();
            }
          }
    }

}

1 个答案:

答案 0 :(得分:1)

请您分享一下究竟有什么慢的详细信息?您要加载的内容是什么?

如果您的代码中存在错误,则会从loadUrl调用shouldOverrideUrlLoading。请不要这样做,只需返回true

SPLASH_LOCK用于什么?你在哪里等呢?