android – AsyncTaskLoader不运行

我想使用兼容包在我的项目中实现一个AsyncTaskLoader,所以我按照Android文档中的Loader手册。

问题是,Loader什么都不做,似乎loadInBackground()从未被调用

任何想法的错误在我的代码?
(ExpandableListFragment extends Fragment,但不会覆盖任何关键方法)

谢谢 :-)

/**编辑:

我意识到(晚,我是一个蠢)AsyncTaskLoader是一个抽象类,所以我需要子类化它… m(__)m
我离开这个问题,以防有人来到我身后,谁知道…

public class AgendaListFragment extends ExpandableListFragment implements
        LoaderManager.LoaderCallbacks<JSONArray> {

    private TreeMap<Integer, ArrayList<Evento>> mItems = new TreeMap<Integer, ArrayList<Evento>>();
    private AgendaListAdapter mAdapter;
    private ProgressBar mProgressBar;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_agenda, container);
        mProgressBar = (ProgressBar) root.findViewById(R.id.loading);
        return root;

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mAdapter = new AgendaListAdapter(getActivity());
        setListAdapter(mAdapter);

        getLoaderManager().initLoader(0, null, this);

    }

    @Override
    public Loader<JSONArray> onCreateLoader(int arg0, Bundle arg1) {
        mProgressBar.setVisibility(View.VISIBLE);
        return new AsyncTaskLoader<JSONArray>(getActivity()) {
            @Override
            public JSONArray loadInBackground() {

                return getDataFromService(AgendaServices.LISTADO_MES);

            }

        };
    }

    @Override
    public void onLoadFinished(Loader<JSONArray> loader, JSONArray data) {

        // Some stuff to turn JSONArray into TreeMap

        mProgressBar.setVisibility(View.GONE);
        mAdapter.setItems(mItems);

    }

    @Override
    public void onLoaderReset(Loader<JSONArray> arg0) {
        mAdapter.setItems(null);
        mProgressBar.setVisibility(View.VISIBLE);

    }

}
我认为,兼容性包的最佳解决方案是重写AsyncTaskLoader.onStartLoading方法。

例如

@Override
protected void onStartLoading() {
  if(dataIsReady) {
    deliverResult(data);
  } else {
    forceLoad();
  }
}
http://stackoverflow.com/questions/8606048/asynctaskloader-doesnt-run

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:android – AsyncTaskLoader不运行