Observable
public
interface
Observable
| androidx.camera.core.Observable<T> |
An observable stream which contains data or errors.
Summary
Nested classes | |
|---|---|
interface |
Observable.Observer<T>
A callback that can receive new values and errors from an |
Public methods | |
|---|---|
abstract
void
|
addObserver(Executor executor, Observer<T> observer)
Adds an observer which will receive the stream of data. |
abstract
ListenableFuture<T>
|
fetchData()
Fetch the latest piece of data asynchronously. |
abstract
void
|
removeObserver(Observer<T> observer)
Removes a previously added observer. |
Public methods
addObserver
public abstract void addObserver (Executor executor,
Observer<T> observer)
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 |
Observer: The observer which will receive new data.
|
fetchData
public abstract ListenableFuture<T> fetchData ()
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.
| Returns | |
|---|---|
ListenableFuture<T> |
A future which will contain the latest value or an error. |
removeObserver
public abstract void removeObserver (Observer<T> observer)
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 |
Observer: The observer to remove.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.