Good load time management practice

I read many answers to solve this problem, but somehow I didn't get the right solution. I start for this reason too.

I am creating a new activity B when a button is clicked on activity A. B has many UIs. It takes about 10 seconds to load. It shows a black screen before.

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 many interface components in this view. My current structure is like this. Now

  • How can I reduce loading times?
  • What is a good method (practice) if the above is not a good way.

Please, please.

+3


source to share


3 answers


If you have about 200 items that are from top to bottom you can try using a ListView, it will handle lazy loading for you. Therefore, when starting the operation, you will only load the visible items. Or try using a different method to implement lazy loading, like take a look at ViewStub. So the main idea here is to split the layout and let it partially load.



+1


source


You can use a progress bar until your UI loads. You should also read the best practice for layout optimization.



0


source


If your activity takes 10 seconds to load, in some cases you have to hit the ANR limit ( http://developer.android.com/training/articles/perf-anr.html ).

Without detailed information about your user interface, I can only guess and offer general advice:

  • Don't initialize all your dialogs at once. Why are you even initializing every dialog? Why do you even need multiple instances of dialogs? Why not just wait until the dialog has been launched before creating the linked object? And why not just maintain a link to the current / last displayed as opposed to all of them?
  • You say you have a lot of OnClickListeners. Make sure you use a single OnClickListener object and just pass the link across multiple views. This way you are only creating one object, not multiple, which might be lucky.
  • Everything you do in onCreate () slows down the launch of the Activity, so limit the work you do there. If it is not needed at the beginning, then initialize it later!
  • To avoid blocking calls on onCreate () / UI thread. That is, any calls to the network or calls to the database. Based on your example, you seem to be fine ... but with a 10 second delay, should you assume you made a blocking call in your onCreate () call (or perhaps onStart () / onResume ()? ). If you need it, use AsyncTask / Thread.

For docs support check out http://developer.android.com/training/articles/perf-tips.html#ObjectCreation (object creation is never free!) Also, I know this has been recommended already, but layout optimization very important if your UI is complex: http://developer.android.com/training/improving-layouts/index.html

Hope it helps! Good luck.

0


source







All Articles