框架整理系列十二(EventBus传值/线程神器)

引用

  compile 'org.greenrobot:eventbus:3.0.0'

使用

Define events:

public static class MessageEvent { /* Additional fields if needed */ }
Prepare subscribers: Declare and annotate your subscribing method, optionally specify a thread mode:

@Subscribe(threadMode = ThreadMode.MAIN)  
public void onMessageEvent(MessageEvent event) {/* Do something */};
Register and unregister your subscriber. For example on Android, activities and fragments should usually register according to their life cycle:

 @Override
 public void onStart() {
     super.onStart();
     EventBus.getDefault().register(this);
 }

 @Override
 public void onStop() {
     super.onStop();
     EventBus.getDefault().unregister(this);
 }
Post events:

 EventBus.getDefault().post(new MessageEvent());

教程

http://blog.csdn.net/harvic880925/article/details/40660137

福利


框架整理系列十二(EventBus传值/线程神器)_第1张图片

你可能感兴趣的:(框架整理系列十二(EventBus传值/线程神器))