This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Using SquidCursorLoader
Sam Bosley edited this page Sep 18, 2015
·
12 revisions
SquidCursorLoader is the analogue to Android's CursorLoader. Instead of querying a ContentResolver to return a Cursor, it queries a SquidDatabase to return a SquidCursor. Queries done with SquidCursorLoader are asynchronous, so they won't block the UI thread waiting for the database.
To construct a SquidCursorLoader, you need an instance of SquidDatabase and a SquiDB Query object. Most often, you will construct a SquidCursorLoader in the context of implementing LoaderCallbacks:
LoaderCallbacks<SquidCursor<Person>> votersLoaderCallbacks =
new LoaderCallbacks<SquidCursor<Person>>() {
@Override
public Loader<SquidCursor<Person>> onCreateLoader(int id, Bundle args) {
Query query = Query.select(Person.PROPERTIES).where(Person.AGE.gt(18));
SquidCursorLoader<Person> loader =
new SquidCursorLoader<Person>(context, database, Person.class, query);
return loader;
}
/* other methods */
};
Optionally, you can call setNotificationUri() to register a Uri to listen for changes on. If the Uri is notified of changes, the loader will be refreshed:
SquidCursorLoader<Person> loader =
new SquidCursorLoader<Person>(context, database, Person.class, query);
loader.setNotificationUri(Person.CONTENT_URI);
See also: