3

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>

Prakhar
  • 710
  • 6
  • 24
  • 3
    please show your code – IntelliJ Amiya Oct 26 '15 at 12:00
  • Maybe with all the activities you have its running a lot of memory? How many activities are running in the stack to get to the slow activity? – SmiffyKmc Oct 26 '15 at 12:02
  • 1
    @IntelliJAmiya added the code – Prakhar Oct 26 '15 at 12:03
  • @koutuk added the xml – Prakhar Oct 26 '15 at 12:03
  • @SmiffyKmc that I don't know, how do I check? Can I know where is the memory leak? – Prakhar Oct 26 '15 at 12:04
  • @Prakhar when you are running the app. At the bottom is your memory output, CPU usage etc. In the memory it will show how much the app is using. Might just be an idea, but maybe you should get into using fragments. It's a really good way to layout your app. Instead of having all the activities you are just swapping the fragment currently viewed to the one you want shown. – SmiffyKmc Oct 26 '15 at 12:08
  • Put debugger on your button click-- when it call check for Internet isNetworkAvailable method ... how much time this method will take to return.... Check n revert – koutuk Oct 26 '15 at 12:10
  • http://developer.android.com/training/articles/memory.html – IntelliJ Amiya Oct 26 '15 at 12:17
  • Better avoid using toast with long length. – Madhukar Hebbar Oct 26 '15 at 12:30
  • It does not seems the posted `RateOrder` class and related xml are complete. Maybe important parts to figure out the problem are still missing (for example, other activity callbacks). – tato.rodrigo Oct 26 '15 at 12:31
  • 1
    are you testing over emulator? – karan Oct 26 '15 at 12:33
  • @tato.rodrigo okk.. so what else shall I post? – Prakhar Oct 26 '15 at 12:46
  • @KaranMer real device – Prakhar Oct 26 '15 at 12:46
  • You should post relevant parts of your code. I'm pretty sure that if you run your activity with only the `onCreate` method it will not load slowly. Are you executing code on your `onResume`, `onStart` or other callbacks? – tato.rodrigo Oct 26 '15 at 12:50
  • @tato.rodrigo no.. I am not using those methods.. just onCreate(), I am calling one async task on button click. But I don't think It should slow down the activity loading time, even if it slows down the button click – Prakhar Oct 26 '15 at 12:54
  • Guys, Removing the weights helped, But I am using weights in other layouts also, that too very heavy nested weights, there it doesn't hang.. then why here? – Prakhar Oct 26 '15 at 13:04

1 Answers1

3

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

Shilpi
  • 498
  • 1
  • 6
  • 13
  • Thank you, Removing the weights helped, But I am using weights in other layouts also, that too very heavy nested weights, there it doesn't hang.. – Prakhar Oct 26 '15 at 13:02
  • Could you please provide the other layout files as well so that I can take a look? – Shilpi Oct 30 '15 at 08:17