diff options
| author | Jeff Brown <jeffbrown@google.com> | 2012-01-25 19:37:13 -0800 |
|---|---|---|
| committer | Jeff Brown <jeffbrown@google.com> | 2012-01-27 17:33:21 -0800 |
| commit | 75ea64fc54f328d37b115cfb1ded1e45c30380ed (patch) | |
| tree | 4254a5d2d0662de8b606b38fea6987da17c130e3 /core/java/android/content/AsyncTaskLoader.java | |
| parent | ebc016c01ea9d5707287cfc19ccc59b21a486c00 (diff) | |
Implement a cancelation mechanism for queries.
Added new API to enable cancelation of SQLite and content provider
queries by means of a CancelationSignal object. The application
creates a CancelationSignal object and passes it as an argument
to the query. The cancelation signal can then be used to cancel
the query while it is executing.
If the cancelation signal is raised before the query is executed,
then it is immediately terminated.
Change-Id: If2c76e9a7e56ea5e98768b6d4f225f0a1ca61c61
Diffstat (limited to 'core/java/android/content/AsyncTaskLoader.java')
| -rw-r--r-- | core/java/android/content/AsyncTaskLoader.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/java/android/content/AsyncTaskLoader.java b/core/java/android/content/AsyncTaskLoader.java index 0b54396ce90a..944ca6b9f33c 100644 --- a/core/java/android/content/AsyncTaskLoader.java +++ b/core/java/android/content/AsyncTaskLoader.java @@ -173,6 +173,7 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { if (DEBUG) Slog.v(TAG, "cancelLoad: cancelled=" + cancelled); if (cancelled) { mCancellingTask = mTask; + onCancelLoadInBackground(); } mTask = null; return cancelled; @@ -256,6 +257,25 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> { } /** + * Override this method to try to abort the computation currently taking + * place on a background thread. + * + * Note that when this method is called, it is possible that {@link #loadInBackground} + * has not started yet or has already completed. + */ + protected void onCancelLoadInBackground() { + } + + /** + * Returns true if the current execution of {@link #loadInBackground()} is being canceled. + * + * @return True if the current execution of {@link #loadInBackground()} is being canceled. + */ + protected boolean isLoadInBackgroundCanceled() { + return mCancellingTask != null; + } + + /** * Locks the current thread until the loader completes the current load * operation. Returns immediately if there is no load operation running. * Should not be called from the UI thread: calling it from the UI |
