Android Webview在5.0(lollipop)以下的速度慢,但在5.0中运行良好

Android Webview在5.0(lollipop)以下的速度慢,但在5.0中运行良好,第1张

概述我面临有关在5.0(lollipop)以下的android中加载网址的问题加载数据太慢,但是在android5.0或更高版本中可以正常工作.如何解决这个问题?Ihavefollowthislink.&Howtoimprovewebviewloadtime我的代码是@SuppressLint({"SetJavaScriptEnabled","DefaultLocale"})

我面临有关在5.0(lollipop)以下的android中加载网址的问题
加载数据太慢,但是在androID 5.0或更高版本中可以正常工作.如何解决这个问题?
I have follow this link.
&
How to improve webview load time

我的代码是

   @Suppresslint({ "SetJavaScriptEnabled", "DefaultLocale" })      public class YS_WebVIEwActivity extends Activity     {    private button btnDone;    private WebVIEw webVIEwLoadUrl;    private YS_GeneralUtility generalUtility;    private Dialog alertDialogBox;    private String url = "";    private TextVIEw tvLoading;    private button btnCancel;    private button btnRetry;    @Suppresslint("InlinedAPI")    @SuppressWarnings("deprecation")    @OverrIDe    protected voID onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_webvIEw);        btnDone = (button) findVIEwByID(R.ID.btnDone);        webVIEwLoadUrl = (WebVIEw) findVIEwByID(R.ID.webVIEwLoadUrl);        //webVIEwLoadUrl.setBackgroundcolor(color.parsecolor("#123456"));        tvLoading = (TextVIEw) findVIEwByID(R.ID.tvLoading);        url = getIntent().getExtras().getString("url");        webVIEwLoadUrl.setVisibility(VIEw.INVISIBLE);        generalUtility = new YS_GeneralUtility(this);        webVIEwLoadUrl.getSettings().setJavaScriptEnabled(true); // enable JavaScript        try {            webVIEwLoadUrl.getSettings().setRenderPriority(RenderPriority.HIGH);             webVIEwLoadUrl.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);            webVIEwLoadUrl.getSettings().setDomStorageEnabled(true);            webVIEwLoadUrl.getSettings().setAllowfileAccess(true);            webVIEwLoadUrl.getSettings().setAllowContentAccess(true);            webVIEwLoadUrl.getSettings().setAllowfileAccessFromfileURLs(true);            //webVIEwLoadUrl.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);        } catch (Exception e) {            e.printstacktrace();        }        tvLoading.setTypeface(generalUtility.faceAvenirlight);        btnDone.setTypeface(generalUtility.faceAvenirMedium);        btnDone.setonClickListener(new OnClickListener()         {            @OverrIDe            public voID onClick(VIEw v)             {                myErrorFinish();            }        });        webVIEwLoadUrl.setWebVIEwClIEnt(new WebVIEwClIEnt()        {            public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw, String url)            {                //Log.i(TAG, "Processing webvIEw url click...");                vIEw.loadUrl(url);                return true;            }            public voID onPageFinished(WebVIEw vIEw, String url)            {                //Log.i(TAG, "Finished loading URL: " + url);                webVIEwLoadUrl.setVisibility(VIEw.VISIBLE);                tvLoading.setVisibility(VIEw.INVISIBLE);            }            String errorData = "<HTML><head></head>"                    + "<body style=' Font-family:Avenir !important;Font-weight:lighter !important; color:#ffffff; margin : 0px auto;'>"                    + "<div style = 'wIDth : 100% ; height : 100% ; background:#123456;'> </div>"                    + "</body></HTML>";            public voID onReceivedError(WebVIEw vIEw, int errorCode, String description, String failingUrl)            {            //  Log.e(TAG, failingUrl + "Error: " + description);                vIEw.loadData(errorData, "text/HTML", "UTF-8");                alertDialogonInternetoff(getString(R.string.errorMsginternet));                // finish();            }            @OverrIDe            public voID onReceivedSslError(WebVIEw vIEw, SslErrorHandler handler, SslError error) {                super.onReceivedSslError(vIEw, handler, error);                handler.proceed();            }        });        webVIEwLoadUrl.loadUrl(url);        // setContentVIEw(webvIEw);    }    private voID alertDialogonInternetoff(String message)    {        alertDialogBox = new Dialog(YS_WebVIEwActivity.this, R.style.InternetErrorPopup);        alertDialogBox.requestwindowFeature(Window.FEATURE_NO_Title);        alertDialogBox.getwindow().setBackgroundDrawable(new colorDrawable(color.transparent));        alertDialogBox.setContentVIEw(R.layout.internetpopup_dialog);        alertDialogBox.setCancelable(false);        alertDialogBox.show();        btnCancel = (button) alertDialogBox.findVIEwByID(R.ID.btnCancel);        btnRetry = (button) alertDialogBox.findVIEwByID(R.ID.btnRetry);        TextVIEw txtExitMessage = (TextVIEw) alertDialogBox.findVIEwByID(R.ID.textVIEwMessage);        TextVIEw horizontallinePopup = (TextVIEw) alertDialogBox.findVIEwByID(R.ID.horizontallinePopup);        TextVIEw verticallinePopup = (TextVIEw) alertDialogBox.findVIEwByID(R.ID.verticallinePopup);        horizontallinePopup.setBackgroundcolor(getResources().getcolor(R.color.internetpopupborderinnerpagecolor));        verticallinePopup.setBackgroundcolor(getResources().getcolor(R.color.internetpopupborderinnerpagecolor));        txtExitMessage.setTypeface(generalUtility.faceAvenirlight);        btnCancel.setTypeface(generalUtility.faceAvenirlight);        btnRetry.setTypeface(generalUtility.faceAvenirlight);        txtExitMessage.setText(R.string.errorMsginternet);        btnCancel.setText(R.string.cancel);        btnRetry.setText(R.string.retry);        alertDialogBox.setCancelable(false);        btnCancel.setonClickListener(new OnClickListener()        {            @OverrIDe            public voID onClick(VIEw v)             {                alertDialogBox.dismiss();                Log.d("AlertDialog", "Negative");                YS_WebVIEwActivity.this.finish();            }        });        btnRetry.setonClickListener(new OnClickListener()        {            @OverrIDe            public voID onClick(VIEw v)            {                alertDialogBox.dismiss();                Log.d("AlertDialog", "Positive");                tvLoading.setVisibility(VIEw.VISIBLE);                webVIEwLoadUrl.loadUrl(url);            }        });    }    private voID myErrorFinish()     {        /*         * Jump to the Setting Screen on pressing back button of device         */        YS_WebVIEwActivity.this.finish();        //overrIDePendingTransition(R.anim.abc_slIDe_in_bottom, R.anim.abc_slIDe_out_bottom);    }    @OverrIDe    public voID onBackpressed()     {        myErrorFinish();        super.onBackpressed();    }  }

这是XML …

     <relativeLayout         androID:ID="@+ID/relativeLayout1"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:background="@drawable/Listback"        androID:orIEntation="vertical" >    <TextVIEw        androID:ID="@+ID/textVIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="42dip"        androID:layout_alignParentleft="true"        androID:layout_alignParentStart="true"        androID:layout_alignParenttop="true"        androID:background="@drawable/navigationbackground" />    <button        androID:ID="@+ID/btnDone"        androID:layout_wIDth="wrap_content"        androID:layout_height="42dip"        androID:layout_alignParentEnd="true"        androID:layout_alignParentRight="true"        androID:layout_alignParenttop="true"        androID:background="@androID:color/transparent"        androID:text="@string/done"        androID:textcolor="@androID:color/white"        androID:textSize="17sp" />    <WebVIEw        androID:ID="@+ID/webVIEwLoadUrl"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_below="@ID/btnDone"        androID:layout_centerVertical="true" />    <TextVIEw        androID:ID="@+ID/tvLoading"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_centerHorizontal="true"        androID:layout_centerVertical="true"        androID:gravity="center"        androID:text="@string/loading"        androID:textcolor="@androID:color/white"        androID:textSize="18sp" />    </relativeLayout>

解决方法:

如果在所有其他答案之后您的问题仍然存在,则需要测试URL /服务器响应和数据格式.

总结

以上是内存溢出为你收集整理的Android Webview在5.0(lollipop)以下的速度慢,但在5.0中运行良好全部内容,希望文章能够帮你解决Android Webview在5.0(lollipop)以下的速度慢,但在5.0中运行良好所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1079496.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存