title: How to update content in Fragment of ViewPager using AsyncTaskLoader?
body: <p>I try to use <code>AsyncTaskLoader</code> in <code>Fragment</code> that is a child of <code>ViewPager</code>. Below a code of my <code>DayFragment</code>:</p>
  
  <pre><code>public class DayFragment extends Fragment
          implements LoaderManager.LoaderCallbacks&lt;DayAdapter.DayItem[]&gt; {
  
      private static final int CONTENT_LOADER = 0;
  
      private DayAdapter mAdapter = null;
      private int mWeekNumber = 1;
      private int mDayCode = 1;
      private Table.Timetable mTimetable;
      private RecyclerView mRVContent;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          final MainActivity mainActivity = (MainActivity) getActivity();
          View v = inflater.inflate(R.layout.content, container, false);
          mRVContent = (RecyclerView) v.findViewById(R.id.rvContent);
          RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mainActivity);
          mRVContent.setLayoutManager(layoutManager);
          mAdapter = new DayAdapter(getActivity());
          mRVContent.setAdapter(mAdapter);
          //Initialize the cursor loader
          getLoaderManager().initLoader(CONTENT_LOADER, null, this).forceLoad();
          return v;
      }
  
      @Override
      public Loader&lt;DayAdapter.DayItem[]&gt; onCreateLoader(final int id, Bundle args) {
  
          if(CONTENT_LOADER == id) {
              return new ContentLoader(getContext(), mWeekNumber, mDayCode, mTimetable);
          }
  
          return null;
      }
  
      @Override
      public void onLoadFinished(Loader loader, DayAdapter.DayItem[] items) {
  
          if(CONTENT_LOADER == loader.getId()) {
              mAdapter.setIs24HourFormat(SettingsManager.is24HourFormat(getContext()));
              mAdapter.clear();
  
              for (DayAdapter.DayItem item : items) {
                  mAdapter.add(item);
              }
  
              mAdapter.notifyDataSetChanged();
  
              if (items.length == 0) {
                  mRVContent.setBackgroundResource(R.drawable.bg_lesson_empty);
              } else {
                  mRVContent.setBackgroundColor(0xFFFFFFFF);
              }
          }
      }
  
      @Override
      public void onLoaderReset(Loader loader) {
  
      }
  
      private static final class ContentLoader extends AsyncTaskLoader&lt;DayAdapter.DayItem[]&gt; {
          private final int mWeekNumber;
          private final int mDayCode;
          private final Table.Timetable mTimetable;
  
          public ContentLoader(Context context, final int weekNumber, final int dayCode,
                               Table.Timetable timetable) {
              super(context);
              mWeekNumber = weekNumber;
              mDayCode = dayCode;
              mTimetable = timetable;
          }
  
          @Override
          public DayAdapter.DayItem[] loadInBackground() {
              DatabaseHandler db = new DatabaseHandler(getContext());
              db.openReadable();
              List&lt;Table.Lesson&gt; lessons = db.findLessons(mDayCode, mWeekNumber, mTimetable.getId());
              DayAdapter.DayItem[] items = new DayAdapter.DayItem[lessons.size()];
  
              for (int i = 0; i &lt; items.length; ++i) {
                  Table.Lesson lesson = lessons.get(i);
  
                  Table.Subject subject = db.getSubject(lesson.getSubjectId());
                  Table.Teacher teacher = db.getTeacher(lesson.getTeacherId());
  
                  if (teacher == null) {
                      teacher = new Table.Teacher(""); //Empty name
                  }
  
                  items[i] = new DayAdapter.DayItem()
                          .setId(lesson.getId())
                          .setTitle(subject.getTitle())
                          .setSubtitle(teacher.getName()));
              }
  
              db.close();
  
              return items;
          }
      }
  }
  </code></pre>
  
  <p><strong><code>PageAdapater</code></strong></p>
  
  <pre><code>public class PageAdapter extends FragmentStatePagerAdapter {
      public static final int PAGE_COUNT = 7;
  
      private int mWeekNumber;
      private final int[] mDayCodes;
      private final String[] mDays;
      private final DayFragment[] mFragments = new DayFragment[7];
      private Table.Timetable mTimetable;
      private boolean mIsRebuildMode = false;
  
      public PageAdapter(Context context, FragmentManager fm,
                         Table.Timetable timetable, final int weekNumber) {
          super(fm);
          //Initialize class members
      }
  
      @Override
      public Fragment getItem(int position) {
          DayFragment dayFragment;
  
          if (mFragments[position] == null) {
              dayFragment = new DayFragment();
              Bundle args = new Bundle();
              args.putSerializable(Keys.TIMETABLE, mTimetable);
              dayFragment.setArguments(args);
              dayFragment.setWeekNumber(mWeekNumber);
              dayFragment.setDayCode(mDayCodes[position]);
              mFragments[position]= dayFragment;
          } else {
              dayFragment = mFragments[position];
          }
  
          return dayFragment;
      }
  
      @Override
      public void restoreState(Parcelable arg0, ClassLoader arg1) {
          //do nothing here! no call to super.restoreState(arg0, arg1);
      }
  
      public void setWeekNumber(final int weekNumber) {
          mWeekNumber = weekNumber;
          Arrays.fill(mFragments, null);
      }
  
      public void setIsRebuildMode(final boolean isRebuildMode) {
          mIsRebuildMode = isRebuildMode;
      }
  
      @Override
      public CharSequence getPageTitle(final int position) {
          return mDays[position];
      }
  
      @Override
      public int getCount() {
          return PAGE_COUNT;
      }
  
      @Override
      public int getItemPosition(Object object) {
  
          if(mIsRebuildMode) {
              return POSITION_NONE;
          }
  
          return super.getItemPosition(object);
      }
  }
  </code></pre>
  
  <p>But it doesn't call <code>onLoadFinished</code> method. I checked <code>Log</code> output... <code>LoaderManager</code> calls <code>onCreateLoader</code> but it never calls <code>onLoadFinished</code> except first run (when app started and <code>ViewPager</code> shows a first page (<code>Fragment</code>)). It's all! After if I switch a page to a next and a next and return to a first page <code>LoaderManager</code> doesn't call <code>onLoadFinished</code> for the first page too. But it creates loader calling <code>onCreateLoader</code> and resets loader calling <code>onLoaderReset</code>. Is it a joke from Google?</p>