eventBus ThreadMode,根据自己的实际使用场景,设置ThreadMode

eventBus 官网ThreadMode介绍:http://greenrobot.org/eventbus/documentation/delivery-threads-threadmode/

具体的使用方法可以参照 git:https://github.com/greenrobot/EventBus,重点记录ThreadMode,可以避免在实际写代码过程中出错。

1.eventBus默认有5中ThreadMode,默认的为ThreadMode: POSTING。

  • 1 ThreadMode: POSTING:默认的Called in the same thread (default),在同一个线程中执行。
  • 2 ThreadMode: MAIN : Called in Android UI's main thread
  • 3 ThreadMode: MAIN_ORDERED: Called in Android UI's main thread ,不过需要排队,如果前一个也是main_ordered 需要等前一个执行完成后才执行,在主线程中执行,可以处理更新ui的操作。
  • 4 ThreadMode: BACKGROUND :Called in the background thread,后台进程,处理如保存到数据库等操作。
  • 5 ThreadMode: ASYNC :Called in a separate thread 异步执行,另起线程操作。
2.使用方法
// Called in the same thread (default)
@ Subscribe ( threadMode = ThreadMode . POSTING )
public void onMessage ( MessageEvent event ) {
     log ( event . message ) ;
}








你可能感兴趣的:(android)