public class CursorLoader
extends AsyncTaskLoader<Cursor>
| java.lang.Object | |||
| android.support.v4.content.Loader<android.database.Cursor> | |||
| android.support.v4.content.AsyncTaskLoader<android.database.Cursor> | |||
| android.support.v4.content.CursorLoader | |||
静态库支持版本的框架CursorLoader 。 用于编写在Android 3.0之前的平台上运行的应用程序。 在Android 3.0或更高版本上运行时,此实现仍在使用; 它不会尝试切换到框架的实现。 请参阅框架SDK文档以了解类概述。
Public constructors |
|
|---|---|
CursorLoader(Context context) 创建一个空的未指定的CursorLoader。 |
|
CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) 创建一个完全指定的CursorLoader。 |
|
公共方法(Public methods) |
|
|---|---|
void |
cancelLoadInBackground() 在主线程上调用以中止正在进行的加载。 |
void |
deliverResult(Cursor cursor) 将加载结果发送给注册的侦听器。 |
void |
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) 将Loader的状态打印到给定的流中。 |
String[] |
getProjection() |
String |
getSelection() |
String[] |
getSelectionArgs() |
String |
getSortOrder() |
Uri |
getUri() |
Cursor |
loadInBackground() 调用工作线程来执行实际加载并返回加载操作的结果。 |
void |
onCanceled(Cursor cursor) 如果任务在完成之前取消,则调用。 |
void |
setProjection(String[] projection) |
void |
setSelection(String selection) |
void |
setSelectionArgs(String[] selectionArgs) |
void |
setSortOrder(String sortOrder) |
void |
setUri(Uri uri) |
Protected methods |
|
|---|---|
void |
onReset() 按照 |
void |
onStartLoading() 开始联系人列表数据的异步加载。 |
void |
onStopLoading() 必须从UI线程调用 |
继承方法(Inherited methods) |
|
|---|---|
android.support.v4.content.AsyncTaskLoader
|
|
android.support.v4.content.Loader
|
|
java.lang.Object
|
|
CursorLoader (Context context)
创建一个空的未指定的CursorLoader。 您必须调用遵循这setUri(Uri) , setSelection(String) ,等指定执行查询。
| 参数(Parameters) | |
|---|---|
context |
Context
|
CursorLoader (Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
创建一个完全指定的CursorLoader。 有关参数含义的文档,请参见ContentResolver.query() 。 这些将按原样传递给该呼叫。
| 参数(Parameters) | |
|---|---|
context |
Context
|
uri |
Uri
|
projection |
String
|
selection |
String
|
selectionArgs |
String
|
sortOrder |
String
|
void cancelLoadInBackground ()
在主线程上调用以中止正在进行的加载。 重写此方法以中止工作线程在后台运行的当前调用loadInBackground() 。 如果loadInBackground()尚未开始运行或已完成,则此方法不应执行任何操作。
void deliverResult (Cursor cursor)
将加载结果发送给注册的侦听器。 只能由子类调用。 必须从进程的主线程中调用。
| 参数(Parameters) | |
|---|---|
cursor |
Cursor: the result of the load |
void dump (String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
将Loader的状态打印到给定的流中。
| 参数(Parameters) | |
|---|---|
prefix |
String: Text to print at the front of each line. |
fd |
FileDescriptor: The raw file descriptor that the dump is being sent to. |
writer |
PrintWriter: A PrintWriter to which the dump is to be set. |
args |
String: Additional arguments to the dump request. |
Cursor loadInBackground ()
调用工作线程来执行实际加载并返回加载操作的结果。 实现不应该直接提供结果,而应该从这个方法返回它们,最终最终会在UI线程上调用deliverResult(D) 。 如果实现需要在UI线程上处理结果,那么它们可以覆盖deliverResult(D)并在那里执行。 为了支持取消,此方法应定期检查isLoadInBackgroundCanceled()的值,并在返回true时终止。 子类也可以覆盖cancelLoadInBackground()直接中断负载,而不是轮询isLoadInBackgroundCanceled() 。 当加载被取消时,这个方法可以正常返回或者抛出OperationCanceledException 。 无论哪种情况, Loader都会调用onCanceled(D)执行取消后清理并处理结果对象(如果有)。
| 返回(Returns) | |
|---|---|
Cursor |
The result of the load operation. |
void onCanceled (Cursor cursor)
如果任务在完成之前取消,则调用。 给班级一个机会清理后取消和妥善处理结果。
| 参数(Parameters) | |
|---|---|
cursor |
Cursor: The value that was returned by loadInBackground(), or null if the task threw OperationCanceledException. |
void onStartLoading ()
开始联系人列表数据的异步加载。 当结果准备就绪时,将在UI线程上调用回调。 如果之前的加载已完成且仍然有效,则结果可能会立即传递给回调。 必须从UI线程调用
void onStopLoading ()
必须从UI线程调用