Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created June 25, 2017 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GauravChaddha1996/56c35f39094c8cba889440e0e026de40 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/56c35f39094c8cba889440e0e026de40 to your computer and use it in GitHub Desktop.
class MainLoader extends Loader<MainPresenter> {
private MainPresenter presenter;
/* When the loader is being created, we instantiate the
presenter also and keep it's object as private */
MainLoader(Context context, MainPresenter presenter) {
super(context);
this.presenter = presenter;
}
/* This function is called when activity is being started.
Hence we deliver the result, our presenter, here. If the
activity is destroyed in rotation, the loader isn't created
again as system made sure it survived the rotation, and
thus when starting of activity calls this function again
automatically and we deliver the pre-rotation presenter as
our result to the activity in onLoadFinished callback*/
@Override
protected void onStartLoading() {
deliverResult(presenter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment