Skip to content

Instantly share code, notes, and snippets.

@skroged
Created September 26, 2014 22:04
Show Gist options
  • Save skroged/99369a34b3e5df771dbe to your computer and use it in GitHub Desktop.
Save skroged/99369a34b3e5df771dbe to your computer and use it in GitHub Desktop.
serial query runnable
public static void query(QueryListener cursorListener, Context context,
Uri uri, String[] cols, String[] selectionArgs,
String selection, String sortOrder) {
new Thread(new QueryRunnable(cursorListener, context,
uri, cols, selectionArgs,
selection, sortOrder)).start();
}
private static class QueryRunnable implements Runnable {
private QueryListener mListener;
private Uri mUri;
private String[] mCols;
private String[] mSelectionArgs;
private String mSelection;
private String mSortOrder;
private Context mContext;
public QueryRunnable(QueryListener cursorListener, Context context,
Uri uri, String[] cols, String[] selectionArgs,
String selection, String sortOrder) {
mListener = cursorListener;
mContext = context;
mSelectionArgs = selectionArgs;
mCols = cols;
mSelection = selection;
mSortOrder = sortOrder;
mUri = uri;
}
@Override
public void run() {
synchronized (lock) {
if (mContext == null) {
return;
}
Cursor cursor = mContext.getContentResolver().query(mUri, mCols, mSelection,
mSelectionArgs, mSortOrder);
mListener.onComplete(cursor);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment