diff --git a/api/current.txt b/api/current.txt
index 983d265c03705..8d6a135ca137b 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -6791,7 +6791,8 @@ package android.database {
public class ContentObservable extends android.database.Observable {
ctor public ContentObservable();
- method public void dispatchChange(boolean);
+ method public deprecated void dispatchChange(boolean);
+ method public void dispatchChange(boolean, android.net.Uri);
method public deprecated void notifyChange(boolean);
method public void registerObserver(android.database.ContentObserver);
}
@@ -6799,8 +6800,10 @@ package android.database {
public abstract class ContentObserver {
ctor public ContentObserver(android.os.Handler);
method public boolean deliverSelfNotifications();
- method public final void dispatchChange(boolean);
+ method public final deprecated void dispatchChange(boolean);
+ method public final void dispatchChange(boolean, android.net.Uri);
method public void onChange(boolean);
+ method public void onChange(boolean, android.net.Uri);
}
public abstract interface CrossProcessCursor implements android.database.Cursor {
diff --git a/core/java/android/content/ContentService.java b/core/java/android/content/ContentService.java
index 9f8bec93644a2..fc4c262e84135 100644
--- a/core/java/android/content/ContentService.java
+++ b/core/java/android/content/ContentService.java
@@ -176,7 +176,7 @@ public final class ContentService extends IContentService.Stub {
for (int i=0; i
* If
+ * If
+ * Subclasses should override this method to handle content changes.
+ *
+ * Subclasses should override this method to handle content changes.
+ * To ensure correct operation on older versions of the framework that
+ * did not provide a Uri argument, applications should also implement
+ * the {@link #onChange(boolean)} overload of this method whenever they
+ * implement the {@link #onChange(boolean, Uri)} overload.
+ *
+ * Example implementation:
+ * selfChange is true, only delivers the notification
* to the observer if it has indicated that it wants to receive self-change
* notifications by implementing {@link ContentObserver#deliverSelfNotifications}
* to return true.
+ * selfChange is true, only delivers the notification
+ * to the observer if it has indicated that it wants to receive self-change
+ * notifications by implementing {@link ContentObserver#deliverSelfNotifications}
+ * to return true.
+ *
+ *
+ * // Implement the onChange(boolean) method to delegate the change notification to
+ * // the onChange(boolean, Uri) method to ensure correct operation on older versions
+ * // of the framework that did not have the onChange(boolean, Uri) method.
+ * {@literal @Override}
+ * public void onChange(boolean selfChange) {
+ * onChange(selfChange, null);
+ * }
*
+ * // Implement the onChange(boolean, Uri) method to take advantage of the new Uri argument.
+ * {@literal @Override}
+ * public void onChange(boolean selfChange, Uri uri) {
+ * // Handle change.
+ * }
+ *
* If a {@link Handler} was supplied to the {@link ContentObserver} constructor, * then a call to the {@link #onChange} method is posted to the handler's message queue. * Otherwise, the {@link #onChange} method is invoked immediately on this thread. + *
* * @param selfChange True if this is a self-change notification. + * + * @deprecated Use {@link #dispatchChange(boolean, Uri)} instead. */ + @Deprecated public final void dispatchChange(boolean selfChange) { + dispatchChange(selfChange, null); + } + + /** + * Dispatches a change notification to the observer. + * Includes the changed content Uri when available. + *+ * If a {@link Handler} was supplied to the {@link ContentObserver} constructor, + * then a call to the {@link #onChange} method is posted to the handler's message queue. + * Otherwise, the {@link #onChange} method is invoked immediately on this thread. + *
+ * + * @param selfChange True if this is a self-change notification. + * @param uri The Uri of the changed content, or null if unknown. + */ + public final void dispatchChange(boolean selfChange, Uri uri) { if (mHandler == null) { - onChange(selfChange); + onChange(selfChange, uri); } else { - mHandler.post(new NotificationRunnable(selfChange)); + mHandler.post(new NotificationRunnable(selfChange, uri)); } } private final class NotificationRunnable implements Runnable { - private final boolean mSelf; + private final boolean mSelfChange; + private final Uri mUri; - public NotificationRunnable(boolean self) { - mSelf = self; + public NotificationRunnable(boolean selfChange, Uri uri) { + mSelfChange = selfChange; + mUri = uri; } @Override public void run() { - ContentObserver.this.onChange(mSelf); + ContentObserver.this.onChange(mSelfChange, mUri); } } @@ -128,10 +189,10 @@ public abstract class ContentObserver { } @Override - public void onChange(boolean selfChange) { + public void onChange(boolean selfChange, Uri uri) { ContentObserver contentObserver = mContentObserver; if (contentObserver != null) { - contentObserver.dispatchChange(selfChange); + contentObserver.dispatchChange(selfChange, uri); } } diff --git a/core/java/android/database/CursorToBulkCursorAdaptor.java b/core/java/android/database/CursorToBulkCursorAdaptor.java index aa0f61e377e44..167278a10b4c9 100644 --- a/core/java/android/database/CursorToBulkCursorAdaptor.java +++ b/core/java/android/database/CursorToBulkCursorAdaptor.java @@ -16,6 +16,7 @@ package android.database; +import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; @@ -78,9 +79,9 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative } @Override - public void onChange(boolean selfChange) { + public void onChange(boolean selfChange, Uri uri) { try { - mRemote.onChange(selfChange); + mRemote.onChange(selfChange, uri); } catch (RemoteException ex) { // Do nothing, the far side is dead } diff --git a/core/java/android/database/IContentObserver.aidl b/core/java/android/database/IContentObserver.aidl index ac2f9754959e3..13aff058a9562 100755 --- a/core/java/android/database/IContentObserver.aidl +++ b/core/java/android/database/IContentObserver.aidl @@ -17,6 +17,8 @@ package android.database; +import android.net.Uri; + /** * @hide */ @@ -27,5 +29,5 @@ interface IContentObserver * observed. selfUpdate is true if the update was caused by a call to * commit on the cursor that is being observed. */ - oneway void onChange(boolean selfUpdate); + oneway void onChange(boolean selfUpdate, in Uri uri); }