Learn about RxJava PublishSubject and how they can act as broadcast agents.
In this lesson you will learn:
- What a PublishSubject is.
- How to create a PublishSubject
- How and when a subscriber will receive items that were emitted from the PublishSubject.
- How terminal events are handled in the PublishSubject.
- How regular and tardy subscribers receive emitted items and events.
Looks like we can use PublishSubject for 1 shot event like showing a Snackbar (or) Toast which we cannot do with LiveData in typical MVVM architecture. I noticed that LiveData is sticky in nature. As soon as it changes its state from inactive to active (like when your fragment was in backstack and it was popped later), LiveData was getting notified and because of that SnackBar was coming again & again.