Android的AsyncTaskLoader不启动loadInBackground? [英] Android AsyncTaskLoader doesn't start loadInBackground?

查看:1208
本文介绍了Android的AsyncTaskLoader不启动loadInBackground?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现在Android上加载器的例子,但不能让它启动加载器。我现在用的是下面的code。它会打创建加载器,但它永远不会达到加载启动日志消息。我失去了一个电话,我需要?

活动:

 公共类TestingZoneActivity扩展ListActivity实现LoaderCallbacks< ArrayList的<内容>> {

        @覆盖
        公共无效的onCreate(包savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.main);

            getLoaderManager()initLoader(0,空,这一点)。
        }

        @覆盖
        公共装载机< ArrayList的<内容>> onCreateLoader(INT ID,捆绑参数){
            Log.e(TEST,创建加载程序);
            返回新ImageLoader的(这一点);
        }

        @覆盖
        公共无效onLoadFinished(装载机< ArrayList的<内容>>装载机,ArrayList的<内容>数据){
            setListAdapter(新ImageAdapter(此,数据));
        }

        @覆盖
        公共无效onLoaderReset(装载机< ArrayList的<内容>>装载机){
            setListAdapter(空);
        }
    }
 

装载机:

 公共类ImageLoader的扩展AsyncTaskLoader< ArrayList的<内容>> {

        公共ImageLoader的(上下文的背景下){
            超(上下文);
        }

        @覆盖
        公众的ArrayList<内容> loadInBackground(){
            Log.e(TEST,加载启动);
        }

    }
 

解决方案

我不得不使用兼容性库同样的问题。 我通过调用解决了的forceload

  getLoaderManager()initLoader(0,空,这一点).forceLoad()。
 

显然对AsyncLoader的文档缺乏,这个问题也存在于蜂窝。更多信息,可以发现这里

AsyncTaskLoader官方例如还呼吁的forceload(),所以它不是一个错误,但我仍然认为,这种行为不是很直观。

I am trying to implement a loader example on Android but can't get it to start the loader. I am using the following code. It will hit the "Create Loader" but it will never reach the "Loading started" log message. Am I missing a call that I need?

Activity:

    public class TestingZoneActivity extends ListActivity implements LoaderCallbacks<ArrayList<Content>>{

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

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

        @Override
        public Loader<ArrayList<Content>> onCreateLoader(int id, Bundle args) {
            Log.e("TEST", "Create Loader");
            return new ImageLoader(this);
        }

        @Override
        public void onLoadFinished(Loader<ArrayList<Content>> loader, ArrayList<Content> data) {
            setListAdapter(new ImageAdapter(this, data));
        }

        @Override
        public void onLoaderReset(Loader<ArrayList<Content>> loader) {
            setListAdapter(null);
        }
    }

Loader:

    public class ImageLoader extends AsyncTaskLoader<ArrayList<Content>> {

        public ImageLoader(Context context) {
            super(context);
        }

        @Override
        public ArrayList<Content> loadInBackground() {
            Log.e("TEST", "Loading started");
        }

    }

解决方案

I had the same problem using the compatibility library. I solved it by calling forceLoad

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

Obviously the documentation on AsyncLoader is lacking and this problem also exists on HoneyComb. More information can be found here

The official example of AsyncTaskLoader is also calling forceLoad() so its not a bug, but i still think that that behavior is not very intuitive.

这篇关于Android的AsyncTaskLoader不启动loadInBackground?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆