The Developer Preview for Android 11 is now available; test it out and share your feedback.


interface Observable<T : Any!>

An observable stream which contains data or errors.


Nested classes


A callback that can receive new values and errors from an Observable.

Public methods

abstract Unit
addObserver(@NonNull executor: Executor, @NonNull observer: Observable.Observer<T>)

Adds an observer which will receive the stream of data.

abstract ListenableFuture<T>

Fetch the latest piece of data asynchronously.

abstract Unit
removeObserver(@NonNull observer: Observable.Observer<T>)

Removes a previously added observer.

Public methods


abstract fun addObserver(@NonNull executor: Executor, @NonNull observer: Observable.Observer<T>): Unit

Adds an observer which will receive the stream of data.

This is an asynchronous operation. Once the observer has been added, it will immediately be called with the latest value contained in the observable if it contains a value, or will be called once a value has been set on the observable.

All added observers should be removed with removeObserver(Observer) when no longer needed.

If the same observer is added twice, it will only be called on the last executor it was registered with.

executor Executor: The executor which will be used to notify the observer of new data.
observer Executor: The observer which will receive new data.


@NonNull abstract fun fetchData(): ListenableFuture<T>

Fetch the latest piece of data asynchronously.

The returned future may also complete with an exception if the observable currently contains an error. If the observable has not yet been initialized with a value, the future may contain an IllegalStateException.

ListenableFuture<T>: A future which will contain the latest value or an error.


abstract fun removeObserver(@NonNull observer: Observable.Observer<T>): Unit

Removes a previously added observer.

Once removed, the observer will no longer receive data.

If the observer was not previously added, this operation will be a no-op.

observer Observable.Observer<T>: The observer to remove.