美文网首页
AsyncTaskLoader

AsyncTaskLoader

作者: acc8226 | 来源:发表于2017-03-09 11:24 被阅读23次
Paste_Image.png

启动
getSupportLoaderManager().initLoader(FORECAST_LOADER_ID, bundleForLoader, callback);

刷新
getSupportLoaderManager().restartLoader(FORECAST_LOADER_ID, bundleForLoader, this);

缓存结果


   return new AsyncTaskLoader<String[]>(this) {

            /* This String array will hold and help cache our weather data */
            String[] mWeatherData = null;

            // COMPLETED (3) Cache the weather data in a member variable and deliver it in onStartLoading.
            /**
             * Subclasses of AsyncTaskLoader must implement this to take care of loading their data.
             */
            @Override
            protected void onStartLoading() {
                if (mWeatherData != null) {
                    deliverResult(mWeatherData);
                } else {
                    mLoadingIndicator.setVisibility(View.VISIBLE);
                    forceLoad();
                }
            }

            ...
            ...
            ...


            /**
             * Sends the result of the load to the registered listener.
             *
             * @param data The result of the load
             */
            public void deliverResult(String[] data) {
                mWeatherData = data;
                super.deliverResult(data);
            }
        };

相关文章

网友评论

      本文标题:AsyncTaskLoader

      本文链接:https://www.haomeiwen.com/subject/lbcwgttx.html