1

"With recent release of Android Support Library, revision 24 Google developers baked into v4 library a new helper class for asynchronous inflation of layouts"

This is my code:

  Timber.e("Timeinflationstarts");
  AsyncLayoutInflater asyncLayoutInflater=newAsyncLayoutInflater(this.getContext());
  asyncLayoutInflater.inflate(R.layout.async_calendar,mLinearLayout,
          new AsyncLayoutInflater.OnInflateFinishedListener() {
      @Override
      public void onInflateFinished(View view, int resid, ViewGroup parent) {

          parent.addView(view);
          Timber.e("timeWhenInflated");
      }
  });

and this is the output:

 07-05 20:36:22.331 18250-18250/? E/PersonalFragment: Timeinflationstarts

 07-05 20:36:22.371 18250-18250/? E/PersonalFragment: timeWhenInflated

the problem is that the view in async_calendar.xml is taking much more time(then 0.04s) to be seen on the screen, blocking the UI thread!

I made the view even heavier to be sure that the lag that I see is much more than 0.04.

1 Answers1

1

It can happen because of several reasons,

For a layout to be inflated asynchronously it needs to have a parent whose generateLayoutParams(AttributeSet) is thread-safe and all the Views being constructed as part of inflation must not create any Handlers or otherwise call myLooper(). If the layout that is trying to be inflated cannot be constructed asynchronously for whatever reason, AsyncLayoutInflater will automatically fall back to inflating on the UI thread.

Also, AsyncLayoutInflater can't be used to inflate layouts that contains fragments. You can learn more in the docs

pepyakin
  • 2,045
  • 16
  • 29