MainThreadSupport
EventBus 3.0 中的代码片段. org.greenrobot.eventbus.MainThreadSupport
定义一个接口,并给出默认实现类. 调用者可以在EventBus的构建者中替换该实现.
public interface MainThreadSupport {
boolean isMainThread();
Poster createPoster(EventBus eventBus);
class AndroidHandlerMainThreadSupport implements MainThreadSupport {
private final Looper looper;
private AndroidHandlerMainThreadSupport(Looper looper) {
this.looper = looper;
}
@Override
public boolean isMainThread() {
return looper == Looper.myLooper();
}
@Override
public Poster createPoster(EventBus eventBus) {
return new HandlerPoster(eventBus, looper, 10);
}
}
}