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. JS实现Tab选项卡

    http://www.jb51.net/article/24694.htm http://www.sunsean.com/idTabs/#t1 http://www.cnblogs.com/sskse ...

  2. centOS7 修改hostname

    hostnamectl set-hostname 你要修改到的hostname   localectl set-locale LANG=要修改的语言     介绍个Centos 7很不错的教程网站:h ...

  3. 正则表达式 regular expression

    原博客地址:http://www.cnblogs.com/deerchao/archive/2006/08/24/zhengzhe30fengzhongjiaocheng.html

  4. dedecms内容页调用缩略图 缩略图多种用法(借鉴)

    文章内容页调用缩略图方法如下两种.第一种没有大小设置.原图显示.第二种.可以设大小, (1) {dede:field.image/} (2)<img src="{dede:field. ...

  5. Core Java Volume I — 1.2. The Java "White Paper" Buzzwords

    1.2. The Java "White Paper" BuzzwordsThe authors of Java have written an influential White ...

  6. java web目录结构

    转自:http://blog.csdn.net/javaloveiphone/article/details/7828894 Javaweb项目的源文件与字节码文件的目录结构 1.新建项目的源文件目录 ...

  7. KVO的简单用法

    KVO,即:Key-Value Observing,它提供一种机制,当指定的对象的属性被修改后,则对象就会接受到通知.简单的说就是每次指定的被观察的对象的属性被修改后,KVO就会自动通知相应的观察者了 ...

  8. SAP 物料移动tcode

    月底,财务月结,需要关账,关闭物料移动功能,支持财务对账: 其中一项任务是要锁定物料移动tcode,这应该是其中部分: CO27 PPIOM000 1000 拣配清单MB1A SAPMM07M 400 ...

  9. 目标跟踪之Lukas-Kanade光流法

    转载自:http://blog.csdn.net/u014568921/article/details/46638557 光流是图像亮度的运动信息描述.光流法计算最初是由Horn和Schunck于19 ...

  10. PHP新手入门1——表单

    注:本身是Android,Android之前是java.但公司后台PHP特别多.就好奇php后台是怎么通过一个url给我数据的(完全不懂php).于是就学呗.学习系列随笔第一人称是一个Android小 ...