Skip to content

Instantly share code, notes, and snippets.

@hkakutalua
Last active April 2, 2018 23:54
Show Gist options
  • Select an option

  • Save hkakutalua/d8fe52d11fcbe744b3c4dc8e0330d0c5 to your computer and use it in GitHub Desktop.

Select an option

Save hkakutalua/d8fe52d11fcbe744b3c4dc8e0330d0c5 to your computer and use it in GitHub Desktop.
Creating and
@Override
public Loader<List<User>> onCreateLoader(int id, Bundle args) {
return new AsyncTaskLoader<List<User>>(this) {
List<User> users;
@Override
protected void onStartLoading() {
super.onStartLoading();
if (users == null) {
forceLoad();
} else {
deliverResult(users);
}
}
@Override
public List<User> loadInBackground() {
try {
return mGithubService.getUsers().execute().body();
} catch (IOException e) {
return null;
}
}
@Override
public void deliverResult(List<User> data) {
super.deliverResult(data);
users = data;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment