Good practices for managing the loading time of the activity

advertisements

I have been reading lot of answers to get this solved, but somehow I didn't get a proper solution. I am a beginer and may be for that reason.

I am creating a new activity B on a button click on activity A. B has lot of UI. So it takes around 10 seconds to load. It shows a black screen till.

public class B extends Activity
{

    Dialog dialog_sec1__participant_name;
    Dialog dialog_sec1__fathers_name;
    Dialog dialog_sec1_address;
    .
    .
    .
    .
    //lot more
    Button btn_section_preview;
    Button btn_sec1_address;
    .
    .
    //lot more

    CustomObj mObject = null;
    CustomObj2 mObject2 = null;
    .
    .
    .

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.B);

    mObject = new CustomObj();
    mObject2 = new CustomObj();
    .
    .

    txt_sec1_preview_household_id=(TextView)findViewById(R.id.a11);
    txt_sec1_preview_date_of_interview=(TextView)findViewById(R.id.a22);
    txt_sec1_preview_time_of_interview=(TextView)findViewById(R.id.a33);
    .
    .
    .
    // Lot more, including setting view to Dialog.

    .
    .
    .
    // and lot of onclick listners

      btn_section_preview.setOnClickListener(new View.OnClickListener()
          {

            @Override
            public void onClick(View arg0)
            {
                //doing my job here
            }
        });
         .
         .
         .
         .

There are lot of UI components in this view. My current structure is like this. Now ,

  1. How I can reduce the load time?
  2. What is a good method ( practise ) to do , if the above way is not a good way .

Please guide me.


If you have about 200 elements that arranges from top to bottom you could try to use ListView, it will handle lazy loading for you. So in starting an activity you will load only visible elements. Or try to use another method to implement lazy loading, look at ViewStub for example. So the main idea here is to divide your layout and allow it to load partially.