Created
September 26, 2014 22:04
-
-
Save skroged/99369a34b3e5df771dbe to your computer and use it in GitHub Desktop.
serial query runnable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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