androidperformanceandroid-viewpager

Android app very slow loading with multiple fragments in view pager


[![enter image description here][1]][1]I am getting crazy. My app has view pager , with 6 fragments. Each fragments has sub-fragments into another viewapager ( ~ 4 fragments for each main fragment). So , total fragments is about 6x4 = 24 fragments. I have set viewPager.setOffscreenPageLimit(max fragment count); to all view pager to make scrolling fast, not laggy

Issue : Very slow app loading , that is variable from device to device , eg :

Lenovo K10 note (L38111) Phone Phone - 6GB RAM -2x2.2 GHz : Loads in 5 seconds Samsung Galaxy A02s(SM-A025F/DS.) Phone - 3GB RAM -1.8GHz : Loads in 90 seconds
Samsung Galaxy A14 Phone - 4GB RAM : Loads in 45 seconds
Samsung Galaxy TAB A - Tablet - 2GB RAM -2.0 GHz : Loads in 7 seconds
Samsung Galaxy S6 Lite - Tablet - 4GB RAM : Loads in 21 seconds

How to accelerate app startup time to be < 10 seconds. And why is this variations in loading time, though it is slow in some android systems with higher specs.

Update : memory stays at 64BM for around 70 seconds, then increase to 140MB in just 3 seconds before app loads

UPDATE -------------------------------------------

I have updated the code to use AsyncLayoutInflater, which has dramatically speed up app startup . below is my code used into each fragment :

View final_view = inflater.inflate(R.layout.loading_view, container, false);
 ProgressBar progressBar = (ProgressBar)final_view.findViewById(R.id.progressBar);

AsyncLayoutInflater asyncInflater = new AsyncLayoutInflater(getActivity());
asyncInflater.inflate(R.layout.customersms_frg, container, new AsyncLayoutInflater.OnInflateFinishedListener() {
    @Override
    public void onInflateFinished(View v, int resid, ViewGroup parent) {

        unbinder = ButterKnife.bind(Customer_SMS.this, v);
       progressBar.setVisibility(View.GONE);
       if (final_view instanceof ViewGroup) {
           ViewGroup viewGroup = (ViewGroup) final_view;
            viewGroup.addView(v);
        }
    }
});

return final_view;

Issue :

app starts in 6 seconds , which is great for me. However, seems that main UI is blocked. ie , when user scroll pager to move to 2nd fragment, >> app not responsive for ~ 20 seconds, then scroll occurrs. I have attached my app trace into https://drive.google.com/file/d/1-Iw1NsF_GBGbKa8dsgzFsZl9xWIHpB9O/view?usp=sharing


Solution

  • How to accelerate app startup time to be < 10 seconds.

    1. Profile your app.
    2. Identify the bottleneck(s).
    3. Optimize.
    4. Go back to 1 until you're satisfied.

    If the slowless is due to inflating layouts, look at AsyncLayoutInflater.

    And why is this variations in loading time, though it is slow in some android systems with higher specs.

    "Higher system specs" is one (or several) of lots of variables. Do all of these devices have the exact same OS version? Disk space? Apps installed? Apps running in the background? Battery level? Etc, etc?