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. Node.js简单介绍并实现一个简单的Web MVC框架

    编号:1018时间:2016年6月13日16:06:41功能:Node.js简单介绍并实现一个简单的Web MVC框架URL :https://cnodejs.org/topic/4f16442cca ...

  2. MyBatis对应的xml的数据类型

    MyBatis对应的xml的数据类型 JDBC Type Java TypeCHAR StringVARCHAR StringLONGVARCHAR StringNUMERIC java.math.B ...

  3. 初识mySQL(关系型数据库)

    一.数据库修改密码 ①先执行use mysql; ②再执行update  mysql.user  set  password=PASSWORD(要修改的密码) where  user='root' ; ...

  4. vs2013 c++代码内出现中文导致编译错误

    简单的做法就是,首先,菜单栏->文件->高级保存选项,选择utf-8 无签名, 然后,如果是发现注释语句里有中文,可以让注释语句与下行代码中间空一行, 如果是代码里有用到中文,那么就在中文 ...

  5. dede取子栏目时重复显示同级栏目的终极解决方法

    使用channelartlist标签时,当栏目没有子栏目是,会出现重复同级栏目的问题,解决方法如下: 先看下面的代码{dede:channelartlist typeid='2'}  {dede:ty ...

  6. 关于项目中用到的流程的sql和表

    select * from FLOW_MAIN SEQCODE FULL_NAME SHORT_NAME FLOW_DESC CREATE_TIME UPDATE_TIME 1 CoursePackF ...

  7. 143. Reorder List

    Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...

  8. Codeforces Round #303 (Div. 2) A 水

    A. Toy Cars time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  9. 一个textview实现文字在图片上面的效果

    类似于这样的,其实很简单,可是以前用的是imageview+textview.布局实现多写了好多代码.又不能在图片加文字,显得没技术含量. xml代码如下: <TextView android: ...

  10. jquery商城购物车右侧悬浮加入购物车动画效果

    <script type="text/javascript" src="js/jquery-1.7.min.js"></script> ...