Android 自定义AsyncTaskLoader,尝试5次后未调用loadinBackground

Android 自定义AsyncTaskLoader,尝试5次后未调用loadinBackground,android,asynctaskloader,Android,Asynctaskloader,我有一个SherlockListFragment,它实现了一个自定义AsyncTaskLoader。 在覆盖的onStartLoading()中,我有: @Override protected void onStartLoading() { if (mData != null) { deliverResult(mData); } else{ forceLoad(); } } 包含的SherlockListFragment在创建的活动中启动加载程序: @Overr

我有一个
SherlockListFragment
,它实现了一个自定义
AsyncTaskLoader
。 在覆盖的
onStartLoading()
中,我有:

@Override
protected void onStartLoading() {
  if (mData != null) {
    deliverResult(mData);
  }
  else{
    forceLoad();
  }
}
包含的
SherlockListFragment
在创建的活动中启动加载程序:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
  super.onActivityCreated(savedInstanceState);
  mAdapter = new MyListAdapter(getActivity());
  setListAdapter(mAdapter);
  getLoaderManager().initLoader(0, null, this);
}
以及:

@覆盖
公共加载器onCreateLoader(int-id,Bundle-args){
返回新的MyListLoader(getActivity());
}
问题是在5次激活/导航到我的FragmentActivity之后,
loadinBackground()
没有被调用。调用了启动加载时的
onStartLoding
,以及
forceLoad
,但仅此而已。 没有例外,日志中没有任何内容


有什么想法吗?

可以调用forceLoad()

请参阅以下文档:
通常只应在加载程序启动时调用此函数,即isStarted()返回true。

完整代码:

@Override
protected void onStartLoading() {
    try {
        if (data != null) {
            deliverResult(data);
        }
        if (takeContentChanged() || data == null) {
            forceLoad();
        }

        Log.d(TAG, "onStartLoading() ");
    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }
}
重要提示: :加载程序
的子类通常必须至少实现onStartLoading()、onStopLoading()、onForceLoad()和onReset()

AsyncTaskLoader扩展了加载程序,但未实现onStartLoading()、onStopLoading()、onReset()。你必须自己去实现它



另外,在经历了使用简单的游标加载程序之后,我对它感到困惑,我还认为使用forceLoad()是不好的做法。但事实并非如此

你在哪里/如何触发活动中的加载程序?你解决过这个问题吗?有一个非常相似的问题。这个问题解决了吗?我在我的项目中遇到了同样的问题;不,我不记得这个问题已经解决了,对不起。在那个项目中,我放弃了Sherlock组件,转而使用v7应用程序compat库。在这个过程中,很多东西都被重写了,我再也没有面对过这个问题。你救了我一天!您是对的,“onStartLoading()”必须实现,即使它不是必需的。在自定义AsyncTaskLoader中实现它解决了我的问题。谢谢
@Override
protected void onStartLoading() {
    try {
        if (data != null) {
            deliverResult(data);
        }
        if (takeContentChanged() || data == null) {
            forceLoad();
        }

        Log.d(TAG, "onStartLoading() ");
    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }
}