DevUtils Github
EventBus 工具类 -> EventBusUtils.java
方法注释
register注册 EventBusunregister解绑 EventBuspost发送事件消息cancelEventDelivery取消事件传送postSticky发送粘性事件消息removeStickyEvent移除指定的粘性订阅事件removeAllStickyEvents移除所有的粘性订阅事件
package dev
.other
;
import org
.greenrobot
.eventbus
.EventBus
;
public final class EventBusUtils {
private EventBusUtils() {
}
public static void register(final Object subscriber
) {
EventBus eventBus
= EventBus
.getDefault();
if (!eventBus
.isRegistered(subscriber
)) {
eventBus
.register(subscriber
);
}
}
public static void unregister(final Object subscriber
) {
EventBus eventBus
= EventBus
.getDefault();
if (eventBus
.isRegistered(subscriber
)) {
eventBus
.unregister(subscriber
);
}
}
public static void post(final Object event
) {
EventBus
.getDefault().post(event
);
}
public static void cancelEventDelivery(final Object event
) {
EventBus
.getDefault().cancelEventDelivery(event
);
}
public static void postSticky(final Object event
) {
EventBus
.getDefault().postSticky(event
);
}
public static <T> void removeStickyEvent(final Class
<T> eventType
) {
T stickyEvent
= EventBus
.getDefault().getStickyEvent(eventType
);
if (stickyEvent
!= null
) {
EventBus
.getDefault().removeStickyEvent(stickyEvent
);
}
}
public static void removeAllStickyEvents() {
EventBus
.getDefault().removeAllStickyEvents();
}
}
转载请注明原文地址: https://mac.8miu.com/read-484802.html