Stay organized with collections
Save and categorize content based on your preferences.
Observable
abstract class Observable<T : Any!>
Provides methods for registering or unregistering arbitrary observers in an ArrayList
. This abstract class is intended to be subclassed and specialized to maintain a registry of observers of specific types and dispatch notifications to them.
Summary
Public methods |
open Unit |
Adds an observer to the list.
|
open Unit |
Remove all registered observers.
|
open Unit |
Removes a previously registered observer.
|
Properties |
ArrayList<T>! |
The list of observers.
|
Public constructors
Public methods
registerObserver
open fun registerObserver(observer: T): Unit
Adds an observer to the list. The observer cannot be null and it must not already be registered.
Parameters |
observer |
T: the observer to register |
Exceptions |
java.lang.IllegalArgumentException |
the observer is null |
java.lang.IllegalStateException |
the observer is already registered |
unregisterAll
open fun unregisterAll(): Unit
Remove all registered observers.
unregisterObserver
open fun unregisterObserver(observer: T): Unit
Removes a previously registered observer. The observer must not be null and it must already have been registered.
Parameters |
observer |
T: the observer to unregister |
Exceptions |
java.lang.IllegalArgumentException |
the observer is null |
java.lang.IllegalStateException |
the observer is not yet registered |
Properties
mObservers
protected val mObservers: ArrayList<T>!
The list of observers. An observer can be in the list at most once and will never be null.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Observable\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nObservable\n==========\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/database/Observable \"View this page in Java\") \n\n```\nabstract class Observable\u003cT : Any!\u003e\n```\n\n|---|----------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.database.Observable](#) |\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [ContentObservable](/reference/kotlin/android/database/ContentObservable), [DataSetObservable](/reference/kotlin/android/database/DataSetObservable) |---------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [ContentObservable](/reference/kotlin/android/database/ContentObservable) | A specialization of [Observable](#) for [ContentObserver](/reference/kotlin/android/database/ContentObserver) that provides methods for sending notifications to a list of [ContentObserver](/reference/kotlin/android/database/ContentObserver) objects. | | [DataSetObservable](/reference/kotlin/android/database/DataSetObservable) | A specialization of [Observable](#) for [DataSetObserver](/reference/kotlin/android/database/DataSetObserver) that provides methods for sending notifications to a list of [DataSetObserver](/reference/kotlin/android/database/DataSetObserver) objects. | |\n\nProvides methods for registering or unregistering arbitrary observers in an [ArrayList](../../java/util/ArrayList.html#). This abstract class is intended to be subclassed and specialized to maintain a registry of observers of specific types and dispatch notifications to them.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------|---|\n| [Observable](#Observable())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [registerObserver](#registerObserver(android.database.Observable.T))`(`observer:` `T`)` Adds an observer to the list. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [unregisterAll](#unregisterAll())`()` Remove all registered observers. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [unregisterObserver](#unregisterObserver(android.database.Observable.T))`(`observer:` `T`)` Removes a previously registered observer. |\n\n| Properties ||\n|----------------------------------------------------|----------------------------------------------------------------------|\n| [ArrayList](../../java/util/ArrayList.html#)\\\u003cT\\\u003e! | [mObservers](#mObservers:java.util.ArrayList) The list of observers. |\n\nPublic constructors\n-------------------\n\n### Observable\n\n```\nObservable()\n```\n\nPublic methods\n--------------\n\n### registerObserver\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun registerObserver(observer: T): Unit\n```\n\nAdds an observer to the list. The observer cannot be null and it must not already be registered.\n\n| Parameters ||\n|------------|-----------------------------|\n| `observer` | T: the observer to register |\n\n| Exceptions ||\n|--------------------------------------|------------------------------------|\n| `java.lang.IllegalArgumentException` | the observer is null |\n| `java.lang.IllegalStateException` | the observer is already registered |\n\n### unregisterAll\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun unregisterAll(): Unit\n```\n\nRemove all registered observers. \n\n### unregisterObserver\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun unregisterObserver(observer: T): Unit\n```\n\nRemoves a previously registered observer. The observer must not be null and it must already have been registered.\n\n| Parameters ||\n|------------|-------------------------------|\n| `observer` | T: the observer to unregister |\n\n| Exceptions ||\n|--------------------------------------|------------------------------------|\n| `java.lang.IllegalArgumentException` | the observer is null |\n| `java.lang.IllegalStateException` | the observer is not yet registered |\n\nProperties\n----------\n\n### mObservers\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nprotected val mObservers: ArrayList\u003cT\u003e!\n```\n\nThe list of observers. An observer can be in the list at most once and will never be null."]]