Git位置https://github.com/greenrobot/EventBus

使用起来很方便:
1. Implement any number of event handling methods in the      subscriber:
     public void      onEvent(AnyEventType event) {}
2. Register subscribers:
     eventBus.register(this);
3. Post events to the bus:
     eventBus.post(event);
4. Unregister subscriber:
     eventBus.unregister(this);

5. public void onEventMainThread(EventType event)方法

两个Activity直接的使用

在第一个Activity的Code如下:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
EventBus.getDefault().register(this);
textView = (TextView)findViewById(R.id.textView);
Button btn_try = (Button)findViewById(R.id.btn_try);
btn_try.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),
SecondActivity.class);
startActivity(intent);
}
});
} @Subscribe
public void onEventMainThread(EventType event){
textView.setText(event.getMessage());
Toast.makeText(this,event.getMessage(),Toast.LENGTH_LONG).show();
}

OnDestory方法

  @Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}

在第二个Activity中使用

 Button btn_first_event = (Button)findViewById(R.id.btn_first_event);
btn_first_event.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EventBus.getDefault().post(new EventType("FistEvent btn cliced"));
}
});

具体实现可参考。

1、《EventBus使用详解(一)——初步使用EventBus》

2、《EventBus使用详解(二)——EventBus使用进阶》

其它参考:

《Android解耦库EventBus的使用和源码分析》:http://blog.csdn.net/yuanzeyao/article/details/38174537

原理很重要哦。

《EventBus的使用初试》:http://blog.csdn.net/pp_hdsny/article/details/14523561

《EventBusExplained  》:https://code.google.com/p/guava-libraries/wiki/EventBusExplained

《Google Guava EventBus实例与分析》

EventBus学习的更多相关文章

  1. EventBus学习入门

    EventBus Features What makes greenrobot's EventBus unique, are its features: Simple yet powerful: Ev ...

  2. EventBus学习笔记(一)

    EventBus是Android和Java的发布/订阅事件总线 EventBus分三个步骤 1.定义事件 public static class MessageEvent { /* Additiona ...

  3. Android组件间通信库EventBus学习

    项目地址:   https://github.com/greenrobot/EventBus EventBus主要特点 1. 事件订阅函数不是基于注解(Annotation)的,而是基于命名约定的,在 ...

  4. EventBus 及一些思考

    EventBus 是 Android 开发的一种常用框架,其解耦的思维令人赞叹 从特性上来讲,其与 Android SDK中的BroadcastReceiver很像,二者都是注册,发送事件,反注册,都 ...

  5. Android学习系列(43)--使用事件总线框架EventBus和Otto

    事件总线框架 针对事件提供统一订阅,发布以达到组件间通信的解决方案. 原理 观察者模式. EventBus和Otto 先看EventBus的官方定义: Android optimized event ...

  6. Guava包学习--EventBus

    之前没用过这个EventBus,然后看了一下EventBus的源码也没看明白,(-__-)b.反正大概就是弄一个优雅的方式实现了观察者模式吧.慢慢深入学习一下. 观察者模式其实就是生产者消费者的一个变 ...

  7. Android 框架学习3:从 EventBus 中学到的精华

    关联文章: EventBus 3.0 的特点与如何使用 源码分析 EventBus 3.0 如何实现事件总线 学习的目的是为了超越,经过前面对 EventBus 3.0 的学习,我们已经对它相当熟悉了 ...

  8. Android 框架学习2:源码分析 EventBus 3.0 如何实现事件总线

    Go beyond yourself rather than beyond others. 上篇文章 深入理解 EventBus 3.0 之使用篇 我们了解了 EventBus 的特性以及如何使用,这 ...

  9. Guava源码学习(五)EventBus

    基于版本:Guava 22.0 Wiki:EventBus 0. EventBus简介 提供了发布-订阅模型,可以方便的在EventBus上注册订阅者,发布者可以简单的将事件传递给EventBus,E ...

随机推荐

  1. WP8.1 实现Continuation程序(打开文件,保存文件等)

    以保存文件为例 首先,在项目中加入ContinuationManager.cs类,以及SuspensionManager.cs类. 其次,在App.xaml.cs中,完成如下步骤: 1. 添加Cont ...

  2. Apache 中 .htaccess 文件设置技巧16则

    .htaccess 文件 (Hypertext Access file) 是Apache Web服务器的一个非常强大的配置文件,对于这个文件,Apache有一堆参数可以让你配置出几乎随心所欲的功能.. ...

  3. 转载blog_Linux下Tomcat日志定期清理 及 logrotate 配置

    服务器上的tomcat的catalina.out文件越来越大,查看起来很不方便,以前每次都是想起来的时候手工清理一下(cat /dev/null > catalina.out),后来发现了log ...

  4. 关于limit hashlimit资料整理

    这几天正在捣鼓防火墙,用到了hashlimit模块.Google了一圈发现相关的文档无论英文还 是中文都很少, 所以我就把自己的折腾的心得记录下来吧. hashlimit是iptables的一个匹配模 ...

  5. JavaScript 阶段总结

  6. Codeforces Round #366 (Div. 2) C 模拟queue

    C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  7. poj 2955 括号匹配 区间dp

    Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6033   Accepted: 3220 Descript ...

  8. CSS Flex弹性布局

    关于css3的flex布局,阮一峰老师的文章写的清晰易懂又全面,这里附上链接http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_s ...

  9. kuangbin_UnionFind C (HDU 1213)

    过程模板 扫一下一共有几棵树 输出 #include <iostream> #include <string> #include <cstdio> #include ...

  10. 论文笔记之:Multiple Object Recognition With Visual Attention

     Multiple Object Recognition With Visual Attention Google DeepMind  ICRL 2015 本文提出了一种基于 attention 的用 ...