No1:

EventBus三要素:

1)Event:事件

2)Subscriber:事件订阅者

3)Publisher:事件发布者

No2:

EventBus的4种ThreadMode(线程模型):

1)POSTING(默认):该事件是在哪个线程发布出来的,事件处理函数就会在哪个线程中运行

2)MAIN:事件的处理会在UI线程中执行

3)BACKGROUND:在新线程或者发布的子线程中执行,禁止进行UI更新操作

4)ASYNC:在新建的子线程中执行,禁止进行UI更新操作

No3:

EventBus源码解析

EventBus.getDefault()->(单例模式)

new EventBus()->

EventBus(EventBusBuilder)->(建造者模式)

register->

SubscriberMethodFinder.findSubscriberMethods->findUsingInfo->getSubscriberInfo->findUsingReflectionInSingleClass->

subscribe->

...

No4:

otto使用

compile 'com.squareup:otto:1.3.8'
public class BusData{
public String message;
public BusData(String message){
this.message = message;
}
public String getMessage(){
return message;
}
public void setMessage(String message){
this.message = message;
}
}
public class OttoBus extends Bus{
private volatile static OttoBus bus;
private OttoBus(){}
public static OttoBus getInstance(){
if(bus == null){
synchronized(OttoBus.class){
if(bus==null){
bus = new OttoBus();
}
}
}
return bus;
}
}
Bus bus = OttoBus.getInstance();
bus.register(this);
bus.unregister(this); @Subscribe
public void setContent(BusData data){
tv_message.setText(data.getMessage());
} OttoBus.getInstance().post(new BusData("刘望舒的博客更新了"));

No5:

Otto主要类的功能

1)Produce、Subscribe:发布者和订阅者注解类

2)Bus:事件总线类,用来注册和取消注册,维护发布-订阅模型,并处理事件调度分发

3)HandlerFinder、AnnotatedHandlerFinder:用来查找发布者和订阅者

4)EventProducer、EventHandler:分别封装发布者和订阅者的数据结构

《Android进阶之光》--事件总线的更多相关文章

  1. [置顶] 曙光到来,我的新书《Android进阶之光》已出版

    独立博客版本请点击这里 由来 2016年我开始建立了自己的知识体系,所有的文章都是围绕着这个体系来写,随着这个体系的慢慢成长,开始有很多出版社联系我写书,因为比较看好电子工业出版社,就顺理成章的开始了 ...

  2. 《Android进阶之光》--Material Design

    接上篇<Android进阶之光>--Android新特性 No1: 组件: 1)底部工作条-Bottom Sheets 2)卡片-Cards 3)提示框-Dialogs 4)菜单-Menu ...

  3. 《Android进阶之光》--注解与依赖注入框架

    No1: 标准注解: 1)@Override:覆写 2)@Deprecated:过时 3)@SuppressWarnings:取消警告 4)@SafeVarargs:申明使用了可变长度参数的方法 No ...

  4. 《Android进阶之光》--RxJava实现RxBus

    事件总线RxBus,替代EventBus和otto 1)创建RxBus public class RxBus{ private static volatile RxBus rxBus; private ...

  5. Android进阶之光-第1章-Android新特性-读书笔记

    第 1 章 Android 新特性 1.1 Android 5.0 新特性 1.1.1 Android 5.0 主要新特性 1. 全新的 Material Design 新风格 Material De ...

  6. 《Android进阶之光》--Android新特性

    Android 5.0新特性 1)全新的Material Design设计风格 2)支持多种设备 3)全新的通知中心设计--按照优先级显示 4)支持64位ART虚拟机 5)多任务视窗Overview ...

  7. 《Android进阶之光》--RxJava

    No1: RxJava使用 dependencies{ compile 'io.reactivex:rxjava:1.2.0' compile 'io.reactivex:rxandroid:1.2. ...

  8. 《Android进阶之光》--Dagger2

    No1: Project的build.gradle文件添加 buildscript{ dependencies{ ...classpath 'com.neenbedankt.gradle.plugin ...

  9. 《Android进阶之光》--ButterKnife

    No1: 添加依赖库 Project的build.gradle文件添加 buildscript{ ... dependencies{ ... classpath 'com.neenbedankt.gr ...

随机推荐

  1. 2018秋寒假作业6- -PTA编程总结3

    PTA3抓老鼠啊~亏了还是赚了?思路: 首先定义变量并初始化为零,然后用if-else语句判断其关系和计算奶酪数量及盈利情况.

  2. [C++]Linux之间隔时间内循环执行指定程序

    #include<time.h> #include<unistd.h>//usleep(num) #include<stdio.h> #include<std ...

  3. luogu P4778 Counting swaps

    计数套路题?但是我连套路都不会,,, 拿到这道题我一脸蒙彼,,,感谢@poorpool 大佬的博客的指点 先将第\(i\)位上的数字\(p_i\)向\(i\)连无向边,然后构成了一个有若干环组成的无向 ...

  4. POJ 1035 Spell checker (模拟)

    题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...

  5. Biorhythms HDU - 1370 (中国剩余定理)

    孙子定理: 当前存在三个式子,t%3=2,t%5=3,t%7=2.然后让你求出t的值的一个通解. 具体过程:选取3和5的一个公倍数t1能够使得这个公倍数t1%7==1,然后选取3和7的一个公倍数t2使 ...

  6. nginx入门一

    配置文件: server_name user root; worker_processes 2; error_log logs/error-test.log; #pid logs/nginx.pid; ...

  7. BIM 相关资料

    BIM 相关资料:http://pan.baidu.com/share/link?shareid=919219072&uk=966240844

  8. Child Process模块

    目录 exec() execSync() execFile() spawn() fork() send() 参考链接 child_process模块用于新建子进程.子进程的运行结果储存在系统缓存之中( ...

  9. shell编程之helloworld

    /bin/sh与/bin/bash的区别sh:如果前面有语句报错,则报错语句后面的命令不执行bash:如果前面有语句报错,后面的命令也会执行sh跟bash的区别,实际上就是bash有没有开启posix ...

  10. 使用ado.net打造通用的数据库操作类

    最近在项目中使用中碰到了这样一种情况,查询的数据是从Oracle中获取的,但是记录下来的数据是存在Sql Server中(企业Oracle数据库管理太严,没办法操作).而且我在之前的工作中也碰到过使用 ...