Create a gist now

Instantly share code, notes, and snippets.

@jdamcd /Loader.java Secret
Last active Sep 26, 2015

void initLoader() {
getLoaderManager().initLoader(LOADER_ID, null, new LoaderManager.LoaderCallbacks<String>() {
@Override
public Loader<String> onCreateLoader(int id, Bundle args) {
return new BackgroundLoader(MainActivity.this);
}
@Override
public void onLoadFinished(Loader<String> loader, String text) {
updateUi(text);
}
@Override
public void onLoaderReset(Loader<String> loader) {
loader.reset();
}
});
}
private static class BackgroundLoader extends AsyncTaskLoader<String> {
public BackgroundLoader(Context context) {
super(context);
}
@Override
protected void onStartLoading() {
forceLoad();
}
@Override
public String loadInBackground() {
return Example.blocking();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment