Added in API level 1

ContentObserver

abstract class ContentObserver
kotlin.Any
   ↳ android.database.ContentObserver

Receives call backs for changes to content. Must be implemented by objects which are added to a ContentObservable.

Summary

Public constructors

Creates a content observer.

Public methods
open Boolean

Returns true if this observer is interested receiving self-change notifications.

Unit
dispatchChange(selfChange: Boolean)

Dispatches a change notification to the observer.

Unit
dispatchChange(selfChange: Boolean, uri: Uri?)

Dispatches a change notification to the observer.

Unit
dispatchChange(selfChange: Boolean, uri: Uri?, flags: Int)

Dispatches a change notification to the observer.

Unit
dispatchChange(selfChange: Boolean, uris: MutableCollection<Uri!>, flags: Int)

Dispatches a change notification to the observer.

open Unit
onChange(selfChange: Boolean)

This method is called when a content change occurs.

open Unit
onChange(selfChange: Boolean, uri: Uri?)

This method is called when a content change occurs.

open Unit
onChange(selfChange: Boolean, uri: Uri?, flags: Int)

This method is called when a content change occurs.

open Unit
onChange(selfChange: Boolean, uris: MutableCollection<Uri!>, flags: Int)

This method is called when a content change occurs.

Public constructors

ContentObserver

Added in API level 1
ContentObserver(handler: Handler!)

Creates a content observer.

Parameters
handler Handler!: The handler to run #onChange on, or null if none.

Public methods

deliverSelfNotifications

Added in API level 1
open fun deliverSelfNotifications(): Boolean

Returns true if this observer is interested receiving self-change notifications. Subclasses should override this method to indicate whether the observer is interested in receiving notifications for changes that it made to the content itself.

Return
Boolean True if self-change notifications should be delivered to the observer.

dispatchChange

Added in API level 1
Deprecated in API level 16
fun dispatchChange(selfChange: Boolean): Unit

Deprecated: Callers should migrate towards using a richer overload that provides more details about the change, such as dispatchChange(boolean,java.util.Collection,int).

Dispatches a change notification to the observer.

If a Handler was supplied to the ContentObserver constructor, then a call to the #onChange method is posted to the handler's message queue. Otherwise, the #onChange method is invoked immediately on this thread.

dispatchChange

Added in API level 16
fun dispatchChange(
    selfChange: Boolean,
    uri: Uri?
): Unit

Dispatches a change notification to the observer. Includes the changed content Uri when available.

If a Handler was supplied to the ContentObserver constructor, then a call to the #onChange method is posted to the handler's message queue. Otherwise, the #onChange method is invoked immediately on this thread.

Parameters
selfChange Boolean: True if this is a self-change notification.
uri Uri?: The Uri of the changed content. This value may be null.

dispatchChange

Added in API level 30
fun dispatchChange(
    selfChange: Boolean,
    uri: Uri?,
    flags: Int
): Unit

Dispatches a change notification to the observer. Includes the changed content Uri when available.

If a Handler was supplied to the ContentObserver constructor, then a call to the #onChange method is posted to the handler's message queue. Otherwise, the #onChange method is invoked immediately on this thread.

Parameters
selfChange Boolean: True if this is a self-change notification.
uri Uri?: The Uri of the changed content. This value may be null.
flags Int: Flags indicating details about this change. Value is either 0 or a combination of android.content.ContentResolver#NOTIFY_SYNC_TO_NETWORK, android.content.ContentResolver#NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, android.content.ContentResolver#NOTIFY_INSERT, android.content.ContentResolver#NOTIFY_UPDATE, and android.content.ContentResolver#NOTIFY_DELETE

dispatchChange

Added in API level 30
fun dispatchChange(
    selfChange: Boolean,
    uris: MutableCollection<Uri!>,
    flags: Int
): Unit

Dispatches a change notification to the observer. Includes the changed content Uris when available.

If a Handler was supplied to the ContentObserver constructor, then a call to the #onChange method is posted to the handler's message queue. Otherwise, the #onChange method is invoked immediately on this thread.

Parameters
selfChange Boolean: True if this is a self-change notification.
uris MutableCollection<Uri!>: The Uri of the changed content. This value cannot be null.
flags Int: Flags indicating details about this change. Value is either 0 or a combination of android.content.ContentResolver#NOTIFY_SYNC_TO_NETWORK, android.content.ContentResolver#NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, android.content.ContentResolver#NOTIFY_INSERT, android.content.ContentResolver#NOTIFY_UPDATE, and android.content.ContentResolver#NOTIFY_DELETE

onChange

Added in API level 1
open fun onChange(selfChange: Boolean): Unit

This method is called when a content change occurs.

Subclasses should override this method to handle content changes.

Parameters
selfChange Boolean: True if this is a self-change notification.

onChange

Added in API level 16
open fun onChange(
    selfChange: Boolean,
    uri: Uri?
): Unit

This method is called when a content change occurs. Includes the changed content Uri when available.

Subclasses should override this method to handle content changes. To ensure correct operation on older versions of the framework that did not provide richer arguments, applications should implement all overloads.

Example implementation:

<code>
  // 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.
  @Override
  public void onChange(boolean selfChange) {
      onChange(selfChange, null);
  }
 
  // Implement the onChange(boolean, Uri) method to take advantage of the new Uri argument.
  @Override
  public void onChange(boolean selfChange, Uri uri) {
      // Handle change.
  }
  </code>

Parameters
selfChange Boolean: True if this is a self-change notification.
uri Uri?: The Uri of the changed content. This value may be null.

onChange

Added in API level 30
open fun onChange(
    selfChange: Boolean,
    uri: Uri?,
    flags: Int
): Unit

This method is called when a content change occurs. Includes the changed content Uri when available.

Subclasses should override this method to handle content changes. To ensure correct operation on older versions of the framework that did not provide richer arguments, applications should implement all overloads.

Parameters
selfChange Boolean: True if this is a self-change notification.
uri Uri?: The Uri of the changed content. This value may be null.
flags Int: Flags indicating details about this change. Value is either 0 or a combination of android.content.ContentResolver#NOTIFY_SYNC_TO_NETWORK, android.content.ContentResolver#NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, android.content.ContentResolver#NOTIFY_INSERT, android.content.ContentResolver#NOTIFY_UPDATE, and android.content.ContentResolver#NOTIFY_DELETE

onChange

Added in API level 30
open fun onChange(
    selfChange: Boolean,
    uris: MutableCollection<Uri!>,
    flags: Int
): Unit

This method is called when a content change occurs. Includes the changed content Uris when available.

Subclasses should override this method to handle content changes. To ensure correct operation on older versions of the framework that did not provide richer arguments, applications should implement all overloads.

Parameters
selfChange Boolean: True if this is a self-change notification.
uris MutableCollection<Uri!>: The Uris of the changed content. This value cannot be null.
flags Int: Flags indicating details about this change. Value is either 0 or a combination of android.content.ContentResolver#NOTIFY_SYNC_TO_NETWORK, android.content.ContentResolver#NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, android.content.ContentResolver#NOTIFY_INSERT, android.content.ContentResolver#NOTIFY_UPDATE, and android.content.ContentResolver#NOTIFY_DELETE