evenbus四种模式 POSTING、MAIN、BACKGROUND、ASYNC
POSTING:默认模式,在哪个线程发布消息就要在哪个线程接受消息
MAIN:指定接受者在主线程接受消息,无论是在哪个线程发布消息
BACKGROUND:指定接受者在子线程接受消息,主线程发布要在子线程接收消息,子线程发布还在他的线程接收消息
ASYNC:指定在子线程接受消息无论是什么线程发布。
evenbus只要处理接受事件的模式就可以,发布事件并不主要
源码:
private void postToSubscription(Subscription subscription, Object event, boolean isMainThread) {
switch (subscription.subscriberMethod.threadMode) {
case POSTING:
invokeSubscriber(subscription, event);
break;
case MAIN:
if (isMainThread) {
invokeSubscriber(subscription, event);
} else {
mainThreadPoster.enqueue(subscription, event);
}
break;
case MAIN_ORDERED:
if (mainThreadPoster != null) {
mainThreadPoster.enqueue(subscription, event);
} else {
// temporary: technically not correct as poster not decoupled from subscriber
invokeSubscriber(subscription, event);
}
break;
case BACKGROUND:
if (isMainThread) {
backgroundPoster.enqueue(subscription, event);
} else {
invokeSubscriber(subscription, event);
}
break;
case ASYNC:
asyncPoster.enqueue(subscription, event);
break;
default:
throw new IllegalStateException("Unknown thread mode: " + subscription.subscriberMethod.threadMode);
}
}
priority 属性 对于相同模式下,priority属性大的优先处理数据。