rxjava PublishSubject second time not subscribe

Publish Subject emits all the subsequent items of the source Observable at the time of subscription. If you want to emit all the items of the source Observable, regardless of when the subscriber subscribes, use Replay Subject.

PublishSubject<Integer> source = PublishSubject.create();

// It will get 1, 2, 3, 4 and onComplete
source.subscribe(getFirstObserver()); 

source.onNext(1);
source.onNext(2);
source.onNext(3);

// It will get 4 and onComplete for second observer also.
source.subscribe(getSecondObserver());

source.onNext(4);
source.onComplete();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top