Reputation: 710
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?
My Java code
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();
}
});
}
and my 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>
Upvotes: 3
Views: 2339
Reputation: 508
Try removing weights from your Xml and see if it helps in loading your activity faster.
Upvotes: 3