您的位置:首页 > 移动开发 > Android开发

android中使用EventBus进行消息通知

2015-08-13 17:15 429 查看
// ------------ 接收消息类,(注册,注销,处理消息)----------

// 注册

EventBus.getDefault().register(this);

// 处理,必须是onEventMainThread(param) para为消息实体类

public void onEventMainThread(MsgBody msg) {

if (msg.getType() == MsgBody.TYPE_1) {

// TODO

}

}

// 注销

EventBus.getDefault().unregister(this);

// ----------- 发送消息类 --------------

EventBus.getDefault().post(new MsgBody(MsgBody.TYPE_1));

// 消息实体类

public class MsgBody{

public static final int TYPE_1 = 1;

private int type;

public MsgBody(int type) {

this.type = type;

}

public int getType() {

return type;

}

public void setType(int type) {

this.type = type;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: