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实现一个异步任务的操作:(图片的下载)