Skip to content

Instantly share code, notes, and snippets.

@julianfalcionelli
Created May 15, 2017 00:44
Show Gist options
  • Save julianfalcionelli/e42fe89b448fe5caed2a18dd3a35f5aa to your computer and use it in GitHub Desktop.
Save julianfalcionelli/e42fe89b448fe5caed2a18dd3a35f5aa to your computer and use it in GitHub Desktop.
Loader
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks {
private int LOADER_ID = 1;
//...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
if (getLoaderManager().getLoader(LOADER_ID) == null) {
getLoaderManager().initLoader(LOADER_ID, null, this).forceLoad();
}
else
getLoaderManager().initLoader(LOADER_ID, null, this);
}
}
@Override
public Loader onCreateLoader(int i, Bundle bundle)
return new ExampleTaskLoader(this);
}
@Override
public void onLoadFinished(Loader loader, Object o)
mTextView.setText((String) o);
}
@Override
public void onLoaderReset(Loader loader)
loader.reset();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment