Making observer registration customizable.

There is a need to skip registering the observer
or register a different observer in cases when
we have an extremely chatty content provider
(think MediaStore).

Change-Id: Iadfb8e0193736cb231762a147c2df1491ad22e0e
This commit is contained in:
Dmitri Plotnikov
2010-09-22 11:04:10 -07:00
parent 5a08b50e80
commit 4d891e7db5
2 changed files with 26 additions and 2 deletions

View File

@@ -46584,6 +46584,21 @@
<parameter name="cursor" type="android.database.Cursor">
</parameter>
</method>
<method name="registerContentObserver"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="cursor" type="android.database.Cursor">
</parameter>
<parameter name="observer" type="android.database.ContentObserver">
</parameter>
</method>
<method name="setProjection"
return="void"
abstract="false"

View File

@@ -16,6 +16,7 @@
package android.content;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
@@ -37,14 +38,22 @@ public class CursorLoader extends AsyncTaskLoader<Cursor> {
public Cursor loadInBackground() {
Cursor cursor = getContext().getContentResolver().query(mUri, mProjection, mSelection,
mSelectionArgs, mSortOrder);
// Ensure the cursor window is filled
if (cursor != null) {
// Ensure the cursor window is filled
cursor.getCount();
cursor.registerContentObserver(mObserver);
registerContentObserver(cursor, mObserver);
}
return cursor;
}
/**
* Registers an observer to get notifications from the content provider
* when the cursor needs to be refreshed.
*/
public void registerContentObserver(Cursor cursor, ContentObserver observer) {
cursor.registerContentObserver(mObserver);
}
/* Runs on the UI thread */
@Override
public void deliverResult(Cursor cursor) {