When a SingleObserver is subscribed to a SingleSource through the SingleSource#subscribe(SingleObserver) method,
the SingleSource calls onSubscribe(Disposable) with a Disposable that allows
disposing the sequence at any time. A well-behaved
SingleSource will call a SingleObserver's onSuccess(Object) method exactly once or the SingleObserver's
onError method exactly once as they are considered mutually exclusive terminal signals.
Calling the SingleObserver's method must happen in a serialized fashion, that is, they must not
be invoked concurrently by multiple threads in an overlapping fashion and the invocation pattern must
adhere to the following protocol:
onSubscribe (onSuccess | onError)?
Subscribing a SingleObserver to multiple SingleSources is not recommended. If such reuse
happens, it is the duty of the SingleObserver implementation to be ready to receive multiple calls to
its methods and ensure proper concurrent behavior of its business logic.
Calling onSubscribe(Disposable), onSuccess(Object) or onError(Throwable) with a
null argument is forbidden.
The implementations of the onXXX methods should avoid throwing runtime exceptions other than the following cases:
null, the methods can throw a NullPointerException.
Note though that RxJava prevents nulls to enter into the flow and thus there is generally no
need to check for nulls in flows assembled from standard sources and intermediate operators.
VirtualMachineError).| Modifier and Type | Method and Description |
|---|---|
| public void | onError(@NonNull Throwable
the exception encountered by the e)SingleNotifies the |
| public void | onSubscribe(@NonNull Disposable
the Disposable instance whose d)Disposable#dispose() can
be called anytime to cancel the connectionProvides the |
| public void | onSuccess(T
the item emitted by the t)SingleNotifies the |
| onError | back to summary |
|---|---|
| public void onError(@NonNull Throwable e) Notifies the
If the | |
| onSubscribe | back to summary |
|---|---|
| public void onSubscribe(@NonNull Disposable d) Provides the
| |
| onSuccess | back to summary |
|---|---|
| public void onSuccess(T t) Notifies the
The
| |