public class CursorLoader
extends AsyncTaskLoader<Cursor>
| java.lang.Object | |||
| android.content.Loader<android.database.Cursor> | |||
| android.content.AsyncTaskLoader<android.database.Cursor> | |||
| android.content.CursorLoader | |||
装载程序查询ContentResolver并返回Cursor 。 该类以查询游标的标准方式实现Loader协议,基于AsyncTaskLoader ,在后台线程上执行游标查询,以便它不会阻塞应用程序的UI。
甲CursorLoader必须的充分信息的查询来执行建立,或者通过 CursorLoader(Context, Uri, String[], String, String[], String)或与创建一个空的实例 CursorLoader(Context)和在期望paramters带装 setUri(Uri) , setSelection(String) , setSelectionArgs(String[]) , setSortOrder(String) ,和 setProjection(String[]) 。
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.content.AsyncTaskLoader
|
|
android.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 setProjection (String[] projection)
| 参数(Parameters) | |
|---|---|
projection |
String
|
void setSelection (String selection)
| 参数(Parameters) | |
|---|---|
selection |
String
|
void setSelectionArgs (String[] selectionArgs)
| 参数(Parameters) | |
|---|---|
selectionArgs |
String
|
void setSortOrder (String sortOrder)
| 参数(Parameters) | |
|---|---|
sortOrder |
String
|
void onReset ()
按照reset() ,子类必须实现此功能,以便重新设置加载程序。 这不是由客户直接呼叫,而是由于致电reset() 。 这将始终从进程的主线程中调用。
void onStartLoading ()
开始联系人列表数据的异步加载。 当结果准备就绪时,将在UI线程上调用回调。 如果之前的加载已完成且仍然有效,则结果可能会立即传递给回调。 必须从UI线程调用