Android Rx编程

1.Rx Reactive Extensions 缩写 是一种响应式编程语言。
reactive: adj. 反应的; 电抗的; 活性的;
extensions: n.延长( extension的名词复数 ); 延伸; [逻辑学] 外延; 扩展名;

Rx可以这样定义: Rx = Observalbes+LINQ +Schedulers(调度程序,日程安排)
LINQ :语言集成查询 (Language Integrated Query)

2.Rx的模式及优点:
Rx模式是 使用了观察者模式:

demo:需要引用的库:
地址: https://github.com/square/picasso 毕加索图片缓存器

 implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'

引入上面这个包可能会造成support版本不一致的问题:
Found versions 28.0.0, 27.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:exifinterface:27.1.0

解决办法:

// picasso po
    implementation('com.squareup.picasso:picasso:2.71828') {
        exclude group: 'com.android.support'
    }

网络请求框架:OKhttp
地址:https://github.com/square/okhttp

implementation("com.squareup.okhttp3:okhttp:3.14.0")

先看下 Rxjava 1.0版本:
引入依赖库:

 implementation "io.reactivex:rxjava:1.1.0"
 implementation 'io.reactivex:rxandroid:1.1.0'

1.0时 rxjava的包名是: package rx;

介绍几个单词:
subscriber :
英 [səbˈskraɪbə®] 美 [səbˈskraɪbər]
n. 用户,订户; <英>(慈善机关等的)定期捐款者; 预约者; 签署者; 在这里订阅者
实现一个被观察者常用的操作符:

create       from(常用数值数组)     interval (定时器每隔几秒)    just(几种不同数据类型整合一块)        range  (范围)      filter(过滤器)

可以用Rxjava实现一个异步任务的操作:(图片的下载)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值