Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GauravChaddha1996/1578c76929dcee64b995fc80a72eee96 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/1578c76929dcee64b995fc80a72eee96 to your computer and use it in GitHub Desktop.
/*Activity.java
- onCreate and other lifecycle stuff */
/*
* Loader API callbacks
* */
/* Here we are creating a new instance of our loader and sending it
the presenter which it will store for future. */
@Override
public Loader<MainPresenter> onCreateLoader(int id, Bundle args) {
return new MainLoader(this, new MainPresenter(new DataManager(this)));
}
/* The deliverResult function from Loader delivers the result
back to us here, as you can see we set our local variable in
activity equal to the presenter that the loaders loads for
us. As initLoader() was called in onCreate(), this load
finishes before onStart() of activity, and thus we can start
using the presenter from onStart(). Also if rotation happens
onCreateLoader() is never called and the load from the
previously created loader is given back to us, i.e. the
pre-rotation presenter. */
@Override
public void onLoadFinished(Loader<MainPresenter> loader, MainPresenter presenter) {
this.presenter = presenter;
}
@Override
public void onLoaderReset(Loader<MainPresenter> loader) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment