compile 'org.greenrobot:eventbus:3.0.0'
//第一种传值 回调传值 相当于
startActivityForResult(); 回调传值
在要接受消息的页面注册
EventBus.getDefault().register(this);
在要接受消息的页面取消注册
@Override protected void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); }
接收消息的方法 传过来对象 方法的形参为对象 传过来字符串方法的形参为字符串 形参为传过来的值 方法名字任意 @Subscribe必须有
@Subscribe
public void onEvent(AnyEventType event) {/* Do something */};
发送消息 event为对象或字符串
EventBus.getDefault().post(event);
第二种为跳转传值
在要接受消息的页面注册
EventBus.getDefault().register(this);
在要接受消息的页面取消注册
@Override protected void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); }
接收消息的方法 传过来对象 方法的形参为对象 传过来字符串方法的形参为字符串 形参为传过来的值 方法名字任意 @Subscribe(sticky = true)必须有
@Subscribe(sticky = true)
public void onEvent(AnyEventType event) {/* Do something */};
发送消息 event为字符串或对象
http://note.youdao.com/noteshare?id=8e4e2b78b084ffe08769bfc02ca83745
EventBus.getDefault().postSticky(event);