Communicating Among Modules
1. Overview - How to communicate among different app modules?
To get the context of the section, please refer this section.
2. Usage tips
We recommend obtaining a single instance of bus through injection or another appropriate mechanism. Alternatively, you may get a singleton like the following:
Or You could provide a getter at your application level class to get the instance of the RxBus. (like we have used).
By default, the Bus enforces that all interactions occur on the main thread.
You can create RxBus like below.
Now, we will create the Singleton(single instance) of RxBus in our application class or at any other place as below:
How to access the RxBus has been mentioned above already.
You can subscribe for an event in any class like below:
You can send an event from any other class or from the same class like below:
This way, you have the EventBus pattern with RxJava, RxBus. But if there is some error, it will terminate, so to avoid that check RxRelay.
RxRelay: A Subject except without the ability to call onComplete or onError.