
启动
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);
}
};
网友评论