CursorLoader
public class CursorLoader extends AsyncTaskLoader
| java.lang.Object | |||
| ↳ | androidx.loader.content.Loader | ||
| ↳ | androidx.loader.content.AsyncTaskLoader | ||
| ↳ | androidx.loader.content.CursorLoader |
Static library support version of the framework's android.content.CursorLoader. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.
Summary
Public constructors |
|---|
CursorLoader(@NonNull Context context)Creates an empty unspecified CursorLoader. |
CursorLoader(Creates a fully-specified CursorLoader. |
Public methods |
|
|---|---|
void |
Called on the main thread to abort a load in progress. |
void |
deliverResult(Cursor data)Sends the result of the load to the registered listener. |
void |
This method is deprecated. Consider using |
@Nullable String[] |
|
@Nullable String |
|
@Nullable String[] |
|
@Nullable String |
|
@NonNull Uri |
getUri() |
Cursor |
Called on a worker thread to perform the actual load and to return the result of the load operation. |
void |
onCanceled(Cursor data)Called if the task was canceled before it was completed. |
void |
setProjection(@Nullable String[] projection) |
void |
setSelection(@Nullable String selection) |
void |
setSelectionArgs(@Nullable String[] selectionArgs) |
void |
setSortOrder(@Nullable String sortOrder) |
void |
Protected methods |
|
|---|---|
void |
onReset()Subclasses must implement this to take care of resetting their loader, as per |
void |
Starts an asynchronous load of the contacts list data. |
void |
Must be called from the UI thread |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
CursorLoader
public CursorLoader(@NonNull Context context)
Creates an empty unspecified CursorLoader. You must follow this with calls to setUri, setSelection, etc to specify the query to perform.
CursorLoader
public CursorLoader(
@NonNull Context context,
@NonNull Uri uri,
@Nullable String[] projection,
@Nullable String selection,
@Nullable String[] selectionArgs,
@Nullable String sortOrder
)
Creates a fully-specified CursorLoader. See ContentResolver.query() for documentation on the meaning of the parameters. These will be passed as-is to that call.
Public methods
cancelLoadInBackground
public void cancelLoadInBackground()
Called on the main thread to abort a load in progress. Override this method to abort the current invocation of loadInBackground that is running in the background on a worker thread. This method should do nothing if loadInBackground has not started running or if it has already finished.
| See also | |
|---|---|
loadInBackground |
deliverResult
public void deliverResult(Cursor data)
Sends the result of the load to the registered listener. Should only be called by subclasses. Must be called from the process's main thread.
| Parameters | |
|---|---|
Cursor data |
the result of the load |
loadInBackground
public Cursor loadInBackground()
Called on a worker thread to perform the actual load and to return the result of the load operation. Implementations should not deliver the result directly, but should return them from this method, which will eventually end up calling deliverResult on the UI thread. If implementations need to process the results on the UI thread they may override deliverResult and do so there. To support cancellation, this method should periodically check the value of isLoadInBackgroundCanceled and terminate when it returns true. Subclasses may also override cancelLoadInBackground to interrupt the load directly instead of polling isLoadInBackgroundCanceled. When the load is canceled, this method may either return normally or throw OperationCanceledException. In either case, the Loader will call onCanceled to perform post-cancellation cleanup and to dispose of the result object, if any.
| Returns | |
|---|---|
Cursor |
The result of the load operation. |
| Throws | |
|---|---|
androidx.core.os.OperationCanceledException |
if the load is canceled during execution. |
onCanceled
public void onCanceled(Cursor data)
Called if the task was canceled before it was completed. Gives the class a chance to clean up post-cancellation and to properly dispose of the result.
| Parameters | |
|---|---|
Cursor data |
The value that was returned by |
Protected methods
onReset
protected void onReset()
Subclasses must implement this to take care of resetting their loader, as per reset. This is not called by clients directly, but as a result of a call to reset. This will always be called from the process's main thread.
onStartLoading
protected void onStartLoading()
Starts an asynchronous load of the contacts list data. When the result is ready the callbacks will be called on the UI thread. If a previous load has been completed and is still valid the result may be passed to the callbacks immediately. Must be called from the UI thread