MainThreadSupport

只谈情不闲聊 提交于 2019-11-29 21:59:56

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);
        }
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!