Android AsyncTaskLoader doesn't start loadInBackground?

后端 未结 6 1587
有刺的猬
有刺的猬 2021-01-30 10:23

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 re

6条回答
  •  野性不改
    2021-01-30 10:39

    Since none of the answers here (besides the accepted one) alone helped me to solve this, here is how it worked for me.

    I don't think the accepted answer is the correct solution, since it causes loadInBackground() to be called more often than necessary, i.e. on orientation change, which does not happen when properly overriding the following methods in the loader as well:

    @Override
    public void deliverResult(final List data) {
        participants = data;
    
        if (isStarted()) {
            super.deliverResult(data);
        }
    
    }
    
    @Override
    protected void onStartLoading() {
        if (takeContentChanged() || participants == null) {
            forceLoad();
        }
    }
    

提交回复
热议问题