The Android Developer Challenge is back! Submit your idea before December 2.

Observable

interface Observable<T : Any!>
androidx.camera.core.Observable

An observable stream which contains data or errors.

Summary

Nested classes

abstract

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

addObserver

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.

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

fetchData

@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.

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

removeObserver

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.

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