Consider the following code snippet.
ReplaySubject<List<Object>> subject = ReplaySubject.create();
subject.subscribe(view::mostraListaObjetos);
subject.onNext(getListOnline());
//logo apos essa linha o metodo view.mostrarListaObjetos(lista)
//deveria ser chamado ou estou errado?
The problem is that no matter how many times I call onNext () the observer never gets anything. does anyone have any idea why?
Edited I had summarized the code, but I discovered that this works well, but when I use the flatMapInterable
and toList
operators, I do not receive anything until subject.onComplete()
is called!
Detailed code example.
ReplaySubject<List<Object>> subject = ReplaySubject.create();
subject.flatMapIterable(object -> {
Log.d(TAG, "flatMapIterable: it is called");
return object;
}).doOnEach(objNotification -> Log.d(TAG, "doOnEach: it is called"))
.toList()
.subscribe(obj -> Log.d(TAG, "subscribe: it is only called after subscribe.onComplete()"));
subject.onNext(getListOfObjects());
Log.d(TAG, "onComplete:");
subject.onComplete();
Logcat output:
07-04 23:20:38.258 10770-10770/app.package D/TAG: flatMapIterable: it is called
07-04 23:20:38.259 10770-10770/app.package D/TAG: doOnEach: it is called
07-04 23:20:38.259 10770-10770/app.package D/TAG: onComplete:
07-04 23:20:38.260 10770-10770/app.package D/TAG: doOnEach: it is called
07-04 23:20:38.260 10770-10770/app.package D/TAG: it is only called after subscribe.onComplete()