//定義一個事件
Define events:
public class MessageEvent { /* Additional fields if needed */ }
//準備一個訂閱者
Prepare subscribers
Register your subscriber (in your onCreate or in a constructor):
eventBus.register(this);
Declare your subscribing method:
@Subscribe
public void onEvent(AnyEventType event) {/* Do something */};
//釋出一個事件
Post events:
eventBus.post(event);
This getting started guide shows these 3 steps in more detail
05-06 23:38:38.622 9391-9391/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.itheima.demo, PID: 9391
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.itheima.demo/com.itheima.demo.MainActivity}:
org.greenrobot.eventbus.EventBusException: Subscriber class
com.itheima.demo.MainActivity and its super classes have no public
methods with the @Subscribe annotation