This is a simple bus library by Android's broadcast. We can use it very convenient. Send and receive messages are marked by class name, which is in line with our actual engineering application.
compile files('libs/broadcastbus-1.0.jar')
Copy the jar to the lib directory of your project and add the config to build.gradle.
BroadcastBus broadcastBus = new BroadcastBus(this);
Map<Class<?>, OnEventReceive> eventMap = new HashMap<>();
eventMap.put(UserInfoEvent.class, new OnEventReceive<UserInfoEvent>() {
@Override
public void onEvent(UserInfoEvent userInfoEvent) {
Log.d(TAG, "UserInfoEvent onEvent - received: " + userInfoEvent.toString());
}
});
//register a bus event
broadcastBus.register(eventMap);
Between,the UseInfoEvent extends BaseEvent,and implement the Serializable.
broadcastBus.post(userInfoEvent);
Send the bus event and what registered this event will receive this event message.
broadcastBus.unRegister();
You must unregister the bus event when is not used.
You Have any questions and questions in the process of using to send the email to me.
- e-mail : [email protected]
- QQ: 514011021