活动加载缓慢 [英] Activity loads slow

查看:32
本文介绍了活动加载缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的申请中有大约 50 个活动.但是其中一项活动非常慢,我的意思是当我按下按钮进入该活动时,需要很长时间,有时最终会出现黑屏.在那个活动中,我有一个按钮,如果我点击那个按钮,它需要很长时间才能执行.代码很轻,只有一个Button、EditText和一个RatingBar.有其他人经历过吗?

I have around 50 activities in my application. But one of the activities is very slow, I mean when I press button to go to that activity, It takes a long time and sometimes ends up in a black screen. On that activity, I have a button, If I click that button, it takes ages to execute. The code is very light, only one Button, EditText and a RatingBar. Has anybody else experienced it?

我的 Java 代码

public class RateOrder extends AppCompatActivity {

Button submit;
RelativeLayout skip;
RatingBar rate;
EditText feedback;
SharedPreferences sp;
String toastText,ratevalue;
int res_code;
float rateevalue;
SweetAlertDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rate_order);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6FD0EA")));
    skip=(RelativeLayout)findViewById(R.id.skip);
    submit=(Button)findViewById(R.id.ratebtn);
    sp=getSharedPreferences("medieazy",MODE_PRIVATE);
    pDialog=new SweetAlertDialog(this,SweetAlertDialog.PROGRESS_TYPE);
    pDialog.setTitleText("Please wait...");
    rate=(RatingBar)findViewById(R.id.ratingBar);
    feedback=(EditText)findViewById(R.id.feedbackTxt);

    Toast.makeText(getApplicationContext(),getIntent().getStringExtra("orderno"),Toast.LENGTH_LONG).show();
    if(getIntent().getStringExtra("from").equals("address")){
        skip.setVisibility(View.GONE);
        skip.setEnabled(false);
    }


    skip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(RateOrder.this,Login.class));
        }
    });


    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


          if(Utils.isNetworkAvailable(RateOrder.this)){
                if(rateevalue>0){
                    ratevalue=String.valueOf(rateevalue);
                    new SubmitRating().execute();
                }
              else{
                    Toast.makeText(getApplicationContext(),"Please rate",Toast.LENGTH_LONG).show();
                }

            }
            else{
                Toast.makeText(getApplicationContext(),"No Internet Connection",Toast.LENGTH_LONG).show();
            }
        }
    });

    rate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                                    boolean fromUser) {
            // TODO Auto-generated method stub
            rateevalue = rating;

            //  Toast.makeText(getApplicationContext(),ratevalue,Toast.LENGTH_LONG).show();

        }
    });
}

和我的 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:background="#ffffff"
android:orientation="vertical"
tools:context="app.aguai.medieazy.activities.RateOrder">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:id="@+id/imageView8"
        android:layout_margin="40dp"
        android:src="@drawable/thumbsup"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />




    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Congratulations on completing your order\nPlease rate your experience to proceed further."
        android:id="@+id/textView9"
        android:textColor="#000000"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="20dp"/>


    <RatingBar
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/ratingBar"
      android:layout_gravity="center" />

   <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
       android:layout_weight="1"
        android:hint="Leave a comment"
       android:layout_margin="20dp"
        android:id="@+id/feedbackTxt"
        android:layout_gravity="center" />

  <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
      android:layout_weight="1"
      android:layout_margin="20dp"
        android:text="Submit"
        android:drawableLeft="@drawable/rateepng"
        android:layout_marginLeft="20dp"
        android:id="@+id/ratebtn"
        android:background="@drawable/theme_button"
        android:textColor="#ffffff"
       android:layout_gravity="center" />


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/skip"
    android:layout_weight="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="SKIP"
        android:textColor="#000000"
        android:layout_centerInParent="true"/>

</RelativeLayout>

推荐答案

尝试从您的 Xml 中删除权重,看看它是否有助于更快地加载您的活动.

Try removing weights from your Xml and see if it helps in loading your activity faster.

这篇关于活动加载缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆