For sending and receiving events we first need an Event object. Event objects are actually simple POJOs.
public class ArbitaryEvent{
public static final int TYPE_1 = 1;
public static final int TYPE_2 = 2;
private int eventType;
public ArbitaryEvent(int eventType){
this....
For receiving events you need to register your class on the EventBus.
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}
And then subscribe ...
The first thing we need to do it add EventBus to our module's gradle file:
dependencies {
...
compile 'org.greenrobot:eventbus:3.0.0'
...
}
Now we need to create a model for our event. It can contain anything we want to pass along. For now we'll just make an empty class.
public ...