AsyncQueryHandlerpublic abstract class AsyncQueryHandler extends android.os.Handler A helper class to help make handling asynchronous {@link ContentResolver}
queries easier. |
Fields Summary |
---|
private static final String | TAG | private static final boolean | localLOGV | private static final int | EVENT_ARG_QUERY | private static final int | EVENT_ARG_INSERT | private static final int | EVENT_ARG_UPDATE | private static final int | EVENT_ARG_DELETE | final WeakReference | mResolver | private static android.os.Looper | sLooper | private android.os.Handler | mWorkerThreadHandler |
Constructors Summary |
---|
public AsyncQueryHandler(ContentResolver cr)
super();
mResolver = new WeakReference<ContentResolver>(cr);
synchronized (AsyncQueryHandler.class) {
if (sLooper == null) {
HandlerThread thread = new HandlerThread("AsyncQueryWorker");
thread.start();
sLooper = thread.getLooper();
}
}
mWorkerThreadHandler = createHandler(sLooper);
|
Methods Summary |
---|
public final void | cancelOperation(int token)Attempts to cancel operation that has not already started. Note that
there is no guarantee that the operation will be canceled. They still may
result in a call to on[Query/Insert/Update/Delete]Complete after this
call has completed.
mWorkerThreadHandler.removeMessages(token);
| protected android.os.Handler | createHandler(android.os.Looper looper)
return new WorkerHandler(looper);
| public void | handleMessage(android.os.Message msg)
WorkerArgs args = (WorkerArgs) msg.obj;
if (localLOGV) {
Log.d(TAG, "AsyncQueryHandler.handleMessage: msg.what=" + msg.what
+ ", msg.arg1=" + msg.arg1);
}
int token = msg.what;
int event = msg.arg1;
// pass token back to caller on each callback.
switch (event) {
case EVENT_ARG_QUERY:
onQueryComplete(token, args.cookie, (Cursor) args.result);
break;
case EVENT_ARG_INSERT:
onInsertComplete(token, args.cookie, (Uri) args.result);
break;
case EVENT_ARG_UPDATE:
onUpdateComplete(token, args.cookie, (Integer) args.result);
break;
case EVENT_ARG_DELETE:
onDeleteComplete(token, args.cookie, (Integer) args.result);
break;
}
| protected void | onDeleteComplete(int token, java.lang.Object cookie, int result)Called when an asynchronous delete is completed.
// Empty
| protected void | onInsertComplete(int token, java.lang.Object cookie, android.net.Uri uri)Called when an asynchronous insert is completed.
// Empty
| protected void | onQueryComplete(int token, java.lang.Object cookie, android.database.Cursor cursor)Called when an asynchronous query is completed.
// Empty
| protected void | onUpdateComplete(int token, java.lang.Object cookie, int result)Called when an asynchronous update is completed.
// Empty
| public final void | startDelete(int token, java.lang.Object cookie, android.net.Uri uri, java.lang.String selection, java.lang.String[] selectionArgs)This method begins an asynchronous delete. When the delete operation is
done {@link #onDeleteComplete} is called.
// Use the token as what so cancelOperations works properly
Message msg = mWorkerThreadHandler.obtainMessage(token);
msg.arg1 = EVENT_ARG_DELETE;
WorkerArgs args = new WorkerArgs();
args.handler = this;
args.uri = uri;
args.cookie = cookie;
args.selection = selection;
args.selectionArgs = selectionArgs;
msg.obj = args;
mWorkerThreadHandler.sendMessage(msg);
| public final void | startInsert(int token, java.lang.Object cookie, android.net.Uri uri, ContentValues initialValues)This method begins an asynchronous insert. When the insert operation is
done {@link #onInsertComplete} is called.
// Use the token as what so cancelOperations works properly
Message msg = mWorkerThreadHandler.obtainMessage(token);
msg.arg1 = EVENT_ARG_INSERT;
WorkerArgs args = new WorkerArgs();
args.handler = this;
args.uri = uri;
args.cookie = cookie;
args.values = initialValues;
msg.obj = args;
mWorkerThreadHandler.sendMessage(msg);
| public void | startQuery(int token, java.lang.Object cookie, android.net.Uri uri, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String orderBy)This method begins an asynchronous query. When the query is done
{@link #onQueryComplete} is called.
// Use the token as what so cancelOperations works properly
Message msg = mWorkerThreadHandler.obtainMessage(token);
msg.arg1 = EVENT_ARG_QUERY;
WorkerArgs args = new WorkerArgs();
args.handler = this;
args.uri = uri;
args.projection = projection;
args.selection = selection;
args.selectionArgs = selectionArgs;
args.orderBy = orderBy;
args.cookie = cookie;
msg.obj = args;
mWorkerThreadHandler.sendMessage(msg);
| public final void | startUpdate(int token, java.lang.Object cookie, android.net.Uri uri, ContentValues values, java.lang.String selection, java.lang.String[] selectionArgs)This method begins an asynchronous update. When the update operation is
done {@link #onUpdateComplete} is called.
// Use the token as what so cancelOperations works properly
Message msg = mWorkerThreadHandler.obtainMessage(token);
msg.arg1 = EVENT_ARG_UPDATE;
WorkerArgs args = new WorkerArgs();
args.handler = this;
args.uri = uri;
args.cookie = cookie;
args.values = values;
args.selection = selection;
args.selectionArgs = selectionArgs;
msg.obj = args;
mWorkerThreadHandler.sendMessage(msg);
|
|