Loaders in Android Honeycomb

前端 未结 3 2068
野的像风
野的像风 2021-01-30 17:23

I\'m trying to figure out how to use Loaders in Android 3.0 but can\'t seem to get it to work. The docs only describe using CursorLoader but I\'m using

相关标签:
3条回答
  • 2021-01-30 17:25

    You need to override the onStartLoading() method. Look at the example on the developer website.

        /**
         * Handles a request to start the Loader.
         */
        @Override protected void onStartLoading() {
            if (mApps != null) {
                // If we currently have a result available, deliver it
                // immediately.
                deliverResult(mApps);
            }
    
            // Start watching for changes in the app data.
            if (mPackageObserver == null) {
                mPackageObserver = new PackageIntentReceiver(this);
            }
    
            // Has something interesting in the configuration changed since we
            // last built the app list?
            boolean configChange = mLastConfig.applyNewConfig(getContext().getResources());
    
            if (takeContentChanged() || mApps == null || configChange) {
                // If the data has changed since the last time it was loaded
                // or is not currently available, start a load.
                forceLoad();
            }
        }
    
    0 讨论(0)
  • 2021-01-30 17:25

    Alex; Did you try to validate if the onLoadInBackground () gets even called?

    onLoadInBackground (): Called on a worker thread to perform the actual load. Implementations should not deliver the result directly, but should return them from this method, which will eventually end up calling deliverResult(D) on the UI thread. If implementations need to process the results on the UI thread they may override deliverResult(D) and do so there.

    0 讨论(0)
  • 2021-01-30 17:48

    Dianne Hackborn replied on the bug tracker and referred us to the static library implementation. CursorLoader is doing forceLoad() which is why it is working.

    See my attached class for a class which handles this for you in most simple cases at the bug tracker: http://code.google.com/p/android/issues/detail?id=14944

    0 讨论(0)
提交回复
热议问题