繁体   English   中英

当启动装载程序并且已经装载了尚未交付给客户端的数据时,场景是什么?

[英]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?

下面的自定义Loader实现的onStartLoading伪代码实现来自此博客文章

您可以看到,根据此方法,当加载程序进入启动状态时(即, onStartLoading ),我们将检查mData是否为非空值;如果该数据为非空值,则我们将立即传递之前加载的任何数据。 问题是,什么情况下已经加载了尚未交付的数据?

最初我以为,可能是加载器从停止状态进入启动状态 ,观察者检测到数据内容发生了变化,并在加载器处于停止状态时加载了数据。 但这是不正确的,因为您已经提到过:“处于停止状态的加载器仍应监视数据源的更改, 以便加载器知道再次启动时会强制执行新的加载。 ”,这意味着加载器会保持监视数据源是否有更改,但不要在停止状态下加载数据,并且当加载程序进入启动状态时,基本上会加载新数据(检测到更改后)。

那么,当装入程序进入启动状态时,在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();
    }
  }

用于重新创建活动的时间(例如轮换期间)。 加载程序已经从以前完成了工作,因此只是重新提供了(重新创建的)活动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM