Loader 启动时已经加载了数据,但还没有交付给客户端的场景是什么?

What is a scenerio in which when a Loader is started and there is already loaded data, which is not yet delivered to the client?

自定义加载器实现的 onStartLoading 的以下伪代码实现取自 this blog post

可以看到,根据这个方法,当一个loader进入started状态,即调用onStartLoading时,我们检查mData是否为not-null,如果为not-null,我们立即提供任何先前加载的数据。 问题是什么是已经加载数据但尚未交付的用例?

一开始我想,可能是loader从停止状态进入启动状态,观察者检测到数据内容发生变化,加载数据的时候装载机处于停止状态。 但事实并非如此,因为你已经提到,"Loaders in the stopped state should still monitor the data source for changes so that the loader will know to force a new load if it is ever started again.",这意味着加载程序会持续监视数据源的变化但不会在停止状态下加载数据,并且当加载程序进入启动状态时,新数据(在检测到更改后)基本上被加载。

那么当loader进入started状态时,有loaded的数据,存储在mData,还没有下发呢?

@Override
  protected void onStartLoading() {
    if (mData != null) {
      // Deliver any previously loaded data immediately.
      deliverResult(mData);
    }

    // Begin monitoring the underlying data source.
    if (mObserver == null) {
      mObserver = new SampleObserver();
      // TODO: register the observer
    }

    if (takeContentChanged() || mData == null) {
      // When the observer detects a change, it should call onContentChanged()
      // on the Loader, which will cause the next call to takeContentChanged()
      // to return true. If this is ever the case (or if the current data is
      // null), we force a new load.
      forceLoad();
    }
  }

它用于重新创建 activity 时(例如在旋转期间)。加载器已经完成了之前的工作,所以它只是重新交付它(重新创建)activity.