http://www.2cto.com/kf/201506/404386.html
http://www.devtf.cn/?p=557&utm_source=tuicool&utm_medium=referral
=========>>>Actvity A
//通知UserRegisterStautsActivity更新状态 EventBus.getDefault().postSticky(new UserRegisterActivity.EventFromUserRegisterActivity_RegisterFailed("未知错误:" + _status));
=========>>>Actvity B
EventBus.getDefault().registerSticky(this);
public void onEventMainThread(UserRegisterActivity.EventFromUserRegisterActivity_RegisterFailed event) {
注意:网上说的那个receiveXXXX()好像不管用
我们并没有在onDestory中对订阅者进行注销,也就是没有调用EventBus的unregister()函数,这就是最新版的特性之一,也是目前唯一不需要手动注销的事件总线库。 这里需要注意是,粘性Sticky事件需要你手动进行移除!EventBus.getDefault().removeStickyEvent(event);
注册EventBus时,当前类必须实现回到函数,否则运行报错:
4-09 23:38:45.745 6096-6096/com.smart.vbox E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smart.vbox, PID: 6096
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smart.vbox/com.smart.vbox.ui.activity.setting.UserRegisterStautsActivity}: de.greenrobot.event.EventBusException: Subscriber class com.smart.vbox.ui.activity.setting.UserRegisterStautsActivity has no public methods called onEvent
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by: de.greenrobot.event.EventBusException: Subscriber class com.smart.vbox.ui.activity.setting.UserRegisterStautsActivity has no public methods called onEvent
at de.greenrobot.event.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:119)
at de.greenrobot.event.EventBus.register(EventBus.java:163)
at de.greenrobot.event.EventBus.registerSticky(EventBus.java:151)
at com.smart.vbox.ui.activity.setting.UserRegisterStautsActivity.onCreate(UserRegisterStautsActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5318)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)