Top Description Methods
io.reactivex.rxjava3.core

public Interface Observer<T>

Known Direct Implementers
io.reactivex.rxjava3.internal.jdk8.ObservableCollectWithCollector.CollectorObserver, io.reactivex.rxjava3.internal.jdk8.ObservableCollectWithCollectorSingle.CollectorSingleObserver, io.reactivex.rxjava3.internal.jdk8.ObservableFlatMapStream.FlatMapStreamObserver, io.reactivex.rxjava3.internal.jdk8.ObservableStageObserver, io.reactivex.rxjava3.internal.observers.DisposableAutoReleaseObserver, io.reactivex.rxjava3.internal.observers.BasicFuseableObserver, io.reactivex.rxjava3.internal.observers.BlockingBaseObserver, io.reactivex.rxjava3.internal.observers.BlockingObserver, io.reactivex.rxjava3.internal.observers.DeferredScalarObserver, io.reactivex.rxjava3.internal.observers.DisposableLambdaObserver, io.reactivex.rxjava3.internal.observers.ForEachWhileObserver, io.reactivex.rxjava3.internal.observers.FutureObserver, io.reactivex.rxjava3.internal.observers.InnerQueuedObserver, io.reactivex.rxjava3.internal.observers.LambdaObserver, io.reactivex.rxjava3.internal.observers.QueueDrainObserver, io.reactivex.rxjava3.internal.operators.completable.CompletableFromObservable.CompletableFromObservableObserver, io.reactivex.rxjava3.internal.operators.flowable.FlowableFromObservable.SubscriberObserver, io.reactivex.rxjava3.internal.operators.mixed.CompletableAndThenObservable.AndThenObservableObserver, io.reactivex.rxjava3.internal.operators.mixed.ConcatMapXMainObserver, io.reactivex.rxjava3.internal.operators.mixed.MaybeFlatMapObservable.FlatMapObserver, io.reactivex.rxjava3.internal.operators.mixed.ObservableSwitchMapCompletable.SwitchMapCompletableObserver, io.reactivex.rxjava3.internal.operators.mixed.ObservableSwitchMapMaybe.SwitchMapMaybeMainObserver, io.reactivex.rxjava3.internal.operators.mixed.ObservableSwitchMapSingle.SwitchMapSingleMainObserver, io.reactivex.rxjava3.internal.operators.mixed.SingleFlatMapObservable.FlatMapObserver, io.reactivex.rxjava3.internal.operators.observable.BlockingObservableIterable.BlockingObservableIterator, io.reactivex.rxjava3.internal.operators.observable.ObservableAll.AllObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableAllSingle.AllObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableAmb.AmbInnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableAny.AnyObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableAnySingle.AnyObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableBuffer.BufferExactObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableBuffer.BufferSkipObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableBufferBoundary.BufferBoundaryObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableBufferBoundary.BufferBoundaryObserver.BufferOpenObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableBufferBoundary.BufferCloseObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableObserveOn.ObserveOnObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableOnErrorComplete.OnErrorCompleteObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableOnErrorNext.OnErrorNextObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableOnErrorReturn.OnErrorReturnObserver, io.reactivex.rxjava3.internal.operators.observable.ObservablePublish.PublishConnection, io.reactivex.rxjava3.internal.operators.observable.ObservablePublishSelector.SourceObserver, io.reactivex.rxjava3.internal.operators.observable.ObservablePublishSelector.TargetObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableReduceMaybe.ReduceObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableReduceSeedSingle.ReduceSeedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRefCount.RefCountObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRepeat.RepeatObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRepeatUntil.RepeatUntilObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRepeatWhen.RepeatWhenObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRepeatWhen.RepeatWhenObserver.InnerRepeatObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableReplay.ReplayObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRetryBiPredicate.RetryBiObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRetryPredicate.RepeatObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRetryWhen.RepeatWhenObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableRetryWhen.RepeatWhenObserver.InnerRepeatObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSampleTimed.SampleTimedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSampleWithObservable.SampleMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSampleWithObservable.SamplerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableScan.ScanObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableScanSeed.ScanSeedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSequenceEqual.EqualObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSequenceEqualSingle.EqualObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSingleMaybe.SingleElementObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSingleSingle.SingleElementObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlatMap.MergeObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlatMap.InnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlatMapCompletable.FlatMapCompletableMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlatMapCompletableCompletable.FlatMapCompletableMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlatMapMaybe.FlatMapMaybeObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlatMapSingle.FlatMapSingleObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableFlattenIterable.FlattenIterableObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSkipLast.SkipLastObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSkipLastTimed.SkipLastTimedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSkipUntil.SkipUntilObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSkipUntil.SkipUntil, io.reactivex.rxjava3.internal.operators.observable.ObservableSkipWhile.SkipWhileObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSubscribeOn.SubscribeOnObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSwitchIfEmpty.SwitchIfEmptyObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSwitchMap.SwitchMapObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSwitchMap.SwitchMapInnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTake.TakeObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeLast.TakeLastObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeLastOne.TakeLastOneObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeLastTimed.TakeLastTimedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeUntil.TakeUntilMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeUntil.TakeUntilMainObserver.OtherObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeUntilPredicate.TakeUntilPredicateObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTakeWhile.TakeWhileObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableThrottleFirstTimed.DebounceTimedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableThrottleLatest.ThrottleLatestObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeInterval.TimeIntervalObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDebounceTimed.DebounceTimedObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableGroupBy.GroupByObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableSkip.SkipObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeout.TimeoutObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeout.TimeoutFallbackObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeout.TimeoutConsumer, io.reactivex.rxjava3.internal.operators.observable.ObservableDelay.DelayObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDelaySubscriptionOther.DelayObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDelaySubscriptionOther.DelayObserver.OnComplete, io.reactivex.rxjava3.internal.operators.observable.ObservableDematerialize.DematerializeObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDetach.DetachObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDoFinally.DoFinallyObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDoOnEach.DoOnEachObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableElementAt.ElementAtObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableElementAtMaybe.ElementAtObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableElementAtSingle.ElementAtObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableGroupJoin.LeftRightObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableGroupJoin.LeftRightEndObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableHide.HideDisposable, io.reactivex.rxjava3.internal.operators.observable.ObservableIgnoreElements.IgnoreObservable, io.reactivex.rxjava3.internal.operators.observable.ObservableIgnoreElementsCompletable.IgnoreObservable, io.reactivex.rxjava3.internal.operators.observable.ObservableLastMaybe.LastObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableLastSingle.LastObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableMapNotification.MapNotificationObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableMaterialize.MaterializeObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableMergeWithCompletable.MergeWithObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableMergeWithMaybe.MergeWithObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableMergeWithSingle.MergeWithObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeoutTimed.TimeoutObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeoutTimed.TimeoutFallbackObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableTimeoutTimed.FallbackObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableToList.ToListObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableToListSingle.ToListObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableUnsubscribeOn.UnsubscribeObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableUsing.UsingObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWindow.WindowExactObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWindow.WindowSkipObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWindowBoundary.WindowBoundaryMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWindowBoundarySelector.WindowBoundaryMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWindowBoundarySelector.WindowBoundaryMainObserver.WindowStartObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWindowBoundarySelector.WindowBoundaryMainObserver.WindowEndObserverIntercept, io.reactivex.rxjava3.internal.operators.observable.ObservableWindowTimed.AbstractWindowObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWithLatestFrom.WithLatestFromObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWithLatestFrom.WithLatestFromOtherObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWithLatestFromMany.WithLatestFromObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableWithLatestFromMany.WithLatestInnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableZip.ZipObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableZipIterable.ZipIterableObserver, io.reactivex.rxjava3.internal.operators.observable.ObserverResourceWrapper, io.reactivex.rxjava3.internal.operators.observable.ObservableCache, io.reactivex.rxjava3.internal.operators.observable.ObservableCollect.CollectObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableCollectSingle.CollectObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableCombineLatest.CombinerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMap.SourceObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMap.SourceObserver.InnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMap.ConcatMapDelayErrorObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMap.ConcatMapDelayErrorObserver.DelayErrorInnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMapEager.ConcatMapEagerMainObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMapScheduler.ConcatMapObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMapScheduler.ConcatMapObserver.InnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMapScheduler.ConcatMapDelayErrorObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatMapScheduler.ConcatMapDelayErrorObserver.DelayErrorInnerObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatWithCompletable.ConcatWithObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatWithMaybe.ConcatWithObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableConcatWithSingle.ConcatWithObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableCount.CountObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableCountSingle.CountObserver, io.reactivex.rxjava3.internal.operators.observable.ObservableDebounce.DebounceObserver, io.reactivex.rxjava3.internal.operators.single.SingleDelayWithObservable.OtherSubscriber, io.reactivex.rxjava3.internal.util.EmptyComponent, io.reactivex.rxjava3.observers.DefaultObserver, io.reactivex.rxjava3.observers.DisposableObserver, io.reactivex.rxjava3.observers.ResourceObserver, io.reactivex.rxjava3.observers.SafeObserver, io.reactivex.rxjava3.observers.SerializedObserver, io.reactivex.rxjava3.observers.TestObserver, io.reactivex.rxjava3.observers.TestObserver.EmptyObserver, io.reactivex.rxjava3.subjects.Subject
Type Parameters
<T>
the type of item the Observer expects to observe
Imports
io.reactivex.rxjava3.annotations.NonNull, io.reactivex.rxjava3.disposables.Disposable

Provides a mechanism for receiving push-based notifications.

When an Observer is subscribed to an ObservableSource through the ObservableSource#subscribe(Observer) method, the ObservableSource calls onSubscribe(Disposable) with a Disposable that allows disposing the sequence at any time, then the ObservableSource may call the Observer's onNext method any number of times to provide notifications. A well-behaved ObservableSource will call an Observer's onComplete method exactly once or the Observer's onError method exactly once.

Calling the Observer'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 onNext* (onError | onComplete)?

Subscribing an Observer to multiple ObservableSources is not recommended. If such reuse happens, it is the duty of the Observer implementation to be ready to receive multiple calls to its methods and ensure proper concurrent behavior of its business logic.

Calling onSubscribe(Disposable), onNext(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 (see Rule 2.13 of the Reactive Streams specification):

Violating Rule 2.13 results in undefined flow behavior. Generally, the following can happen:

From the Observable's perspective, an Observer is the end consumer thus it is the Observer's responsibility to handle the error case and signal it "further down". This means unreliable code in the onXXX methods should be wrapped into `try-catch`es, specifically in onError(Throwable) or onComplete(), and handled there (for example, by logging it or presenting the user with an error dialog). However, if the error would be thrown from onNext(Object), Rule 2.13 mandates the implementation calls Disposable#dispose() and signals the exception in a way that is adequate to the target context, for example, by calling onError(Throwable) on the same Observer instance.

If, for some reason, the Observer won't follow Rule 2.13, the Observable#safeSubscribe(Observer) can wrap it with the necessary safeguards and route exceptions thrown from onNext into onError and route exceptions thrown from onError and onComplete into the global error handler via io.reactivex.rxjava3.plugins.RxJavaPlugins#onError(Throwable).

See Also
ReactiveX documentation: Observable

Method Summary

Modifier and TypeMethod and Description
public void
onComplete()

Notifies the Observer that the Observable has finished sending push-based notifications.

public void
onError(@NonNull Throwable
the exception encountered by the Observable
e
)

Notifies the Observer that the Observable has experienced an error condition.

public void
onNext(T
the item emitted by the Observable
t
)

Provides the Observer with a new item to observe.

public void
onSubscribe(@NonNull Disposable
the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection
d
)

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.

Method Detail

onCompleteback to summary
public void onComplete()

Notifies the Observer that the Observable has finished sending push-based notifications.

The Observable will not call this method if it calls onError.

onErrorback to summary
public void onError(@NonNull Throwable e)

Notifies the Observer that the Observable has experienced an error condition.

If the Observable calls this method, it will not thereafter call onNext or onComplete.

Parameters
e:@NonNull Throwable

the exception encountered by the Observable

onNextback to summary
public void onNext(T t)

Provides the Observer with a new item to observe.

The Observable may call this method 0 or more times.

The Observable will not call this method again after it calls either onComplete or onError.

Parameters
t:T

the item emitted by the Observable

onSubscribeback to summary
public void onSubscribe(@NonNull Disposable d)

Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within onNext(Object)) and asynchronous manner.

Parameters
d:@NonNull Disposable

the Disposable instance whose Disposable#dispose() can be called anytime to cancel the connection

Since
2.0