前面说了RxJava 与Retrofit的基本用法,但是没用做优化的处理.本篇先做一个优化处理,然后再结合前面的MVP 设计模式,把这些知识贯穿到一个Demo 之中,方便大家理解....}); 接下来我要说的 就是MVP 设计模式 下 请求网络获取商品列表并展示的过程了 这个是效果图 就是请求网络并获取商品列表的功能 根据之前 MVP 设计模式,外加RxJava...+Retrofit 网络请求 整合在一起 mvp 接口管理类 public interface HomeGoodsContract { interface Model {...*/ @NonNull private Retrofit initRetrofit(OkHttpClient client) { return new Retrofit.Builder....client(client) .baseUrl(Constant.IP) .addCallAdapterFactory(RxJava2CallAdapterFactory.create
说道RxJava+Retrofit 的组合 大家基本不陌生,先介绍一下Retrofit Retrofit 是一个 RESTful 的 HTTP 网络请求框架的封装,网络请求的工作本质上是 OkHttp...Retrofit的使用 先简单介绍一个网络请求的例子,注解之类的放在后面去说 (1) 添加Retrofit库的依赖 implementation "io.reactivex.rxjava2:rxjava...:2.2.0" implementation "io.reactivex.rxjava2:rxandroid:2.0.2" implementation 'com.squareup.retrofit2...:retrofit:2.3.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' implementation...大体使用情况,接下来就简单的介绍RxJava的使用,Retrofit 与RxJava 一百度就很多原理之类的大体说的都差不多,大同小异.我主要以实战为主,如何使用 稍带点基础… 初始化Retrofit的时候的必要配置
: https://github.com/ReactiveX/RxAndroid https://github.com/ReactiveX/RxJava 官网:reactivex.io RxJava...:rxjava:3.0.0” implementation ‘io.reactivex:rxandroid:1.2.1’ implementation ‘com.squareup.retrofit2...和RxJava组合使用时,Retrofit中使用的rxjava适配器(adapter-rxjava3)要和RxJava版本(io.reactivex.rxjava3:rxjava:3.0.0)一致;如本例都是使用的时...3.0;关于先前Rerotfit没有Rxjava3.0适配器问题;android – Which rxjava3 retrofit-adapter should we use for Rxjava3 –...:rxandroid:3.0.0' // Because RxAndroid releases are few and far between, it is recommended you also
RxAndroid是RxJava针对Android平台的拓展。...RxJava GitHub地址:https://github.com/ReactiveX/RxJava RxAndroid GitHub地址:https://github.com/ReactiveX/RxAndroid...调用 weatherInfoService#getWeatherInfo(FORMAT, CITYNAME, KEY),获取call 插入队列,并展示数据 RxJava/RxAndroid结合Retrofit...:2.0.0-beta4' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1' compile 'io.reactivex:rxandroid:...接下来会一一讲解 MainActivity#getWeatherInfo() 在这个方法里实现了最基本的RxJava/RxAndroid和Retrofit的结合。
:如果不使用Rxjava,可不引入rx的包) implementation 'com.squareup.retrofit2:retrofit:2.1.0' //retrofit implementation...'com.google.code.gson:gson:2.6.2' //Gson 库 //下面两个是RxJava 和RxAndroid implementation 'io.reactivex:rxjava...:1.1.0' implementation 'io.reactivex:rxandroid:1.1.0' implementation 'com.squareup.retrofit2:converter-gson...:2.1.0' //转换器,请求结果转换成Model implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 2.2 使用 get...Retrofit+RxJava实现网络请求的简单演示这样就完成了,如果每个接口都这么写的话,代码量太多,而且不优雅。所以还需要我们封装一下,有兴趣的朋友可以自行封装,有好的分享,欢迎投稿。
整合了Rxjava +retrofit+mvp,写完了迫不及待的分享出来了,打算以后的开发都用这个,太强大了,另外OKhTTP用了网络缓存,非常的方便,以后写缓存都不需要写本地数据库了。...引入RXjAVA、RxAndroid、retrofit jar包 compile 'io.reactivex:rxandroid:1.2.1' compile 'com.squareup.retrofit2...:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.squareup.retrofit2...:adapter-rxjava:2.1.0' 关于retrofit的用法,点击见官网。...关于Rxjava的用法, 翻译的Rxjava中文文档 本文是一个整理好的RxJava+retrofit+Mvp的例子。
简述 Retrofit2是square公司出品的一个网络请求库,网上有很多相关的介绍。...get请求 post请求 文件上传 文件下载 开启日志拦截 与RxJava结合使用 什么是Retrofit2 官网是这么介绍的: Retrofit adapts a Java...使用前的配置 build.gradle 的 dependencies 添加: 获取Retrofit实例 Retrofit retrofit = new Retrofit.Builder() .baseUrl...与RxJava结合使用 添加库: compile 'io.reactivex:rxandroid:1.1.0' compile 'com.squareup.retrofit2:adapter-rxjava...public void onNext(BaseResponse managerBaseResponse) { } }); RxJava
使用Material Design设计风格,和流行的MVP+Retrofit+RxJava框架。...25.0.1' //custom tabs compile 'com.android.support:customtabs:25.0.1' compile project(':customtabs')//编译RxJava...compile 'io.reactivex:rxjava:1.1.6' //编译RxAndroid compile 'io.reactivex:rxandroid:1.2.1' //编译Retrofit...及其相关库,包括Gson compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.squareup.retrofit2:retrofit:2.1.0...' compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.squareup.retrofit2:adapter-rxjava
] 集成RxJava2和Retrofit2 // Rx compile rootProject.ext.dependencies["rxjava"] compile rootProject.ext.dependencies...:rxjava:${dependVersion.rxJava}", "rxandroid" : "io.reactivex.rxjava2...:rxandroid:${dependVersion.rxandroid}", "rxpermissions" : "com.tbruyelle.rxpermissions2...: "com.squareup.retrofit2:converter-gson:${dependVersion.retrofit}", "retrofit-adapter-rxjava2..." : "com.squareup.retrofit2:adapter-rxjava2:${dependVersion.retrofit}", // 网络日志拦截
: "com.squareup.retrofit2:retrofit:$dependVersion.retrofit2_version", retrofit_converters...: "com.squareup.retrofit2:adapter-rxjava2:$dependVersion.retrofit2_version"] gson = [gson: "com.google.code.gson...:gson:$dependVersion.gson_version"] rxandroid = [rxandroid: "io.reactivex.rxjava2:rxandroid:$dependVersion.rxandroid_version..."] rxjava = [rxjava: "io.reactivex.rxjava2:rxjava:$dependVersion.rxjava_version"] //*******....Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory import retrofit2.converter.gson.GsonConverterFactory
exclude 'META-INF/rxjava.properties' } 一般出现这种问题是同时依赖的了 rxjava1 & rxjava2 的依赖,也包含不同版本的适配器。...RxJava1.x & RxJava2.x 依赖区别 RxJava1.x 相关依赖 implementation 'io.reactivex:rxjava:1.3.0' implementation '...io.reactivex:rxandroid:1.2.1' implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0' RxJava2.x...相关依赖 implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'io.reactivex.rxjava2:rxjava...:2.1.1' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0' 记忆:有 rxjava2 就是 2.x 否则就是 1.x 。
okhttp-OkGo compile 'com.lzy.net:okgo:3.0.4' ★★★ okhttputils compile 'com.zhy:okhttputils:2.6.2' ★★停止维护 retrofit...compile 'com.squareup.retrofit2:retrofit:2.1.0' ★★ xUtils3 compile 'org.xutils:xutils:3.3.38' ★★ JSON...RxBus compile 'com.hwangjr.rxbus:rxbus:1.0.5' ★★项目使用Rxjava 作者好长时间未更新 otto compile 'com.squareup:otto...:3.3.38' ★★ 事件视图绑定 名称 引用方式 个人推荐 butterknife 见官网 ★★★ xUtils3 compile 'org.xutils:xutils:3.3.38' ★★ RxAndroid...RxAndroid implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' implementation 'io.reactivex.rxjava2
此博文根据前面两篇文章 Android MVP 架构初试 Android MVP 架构封装 再结合主流框架Retrofit2+Rxjava来个实践(实现聚合网周公解梦) 源码地址RxMVP 项目截图...Retrofit2+Rxjava 封装 JuHeService 数据请求接口 /** * 请求示例: * http://v.juhe.cn/dream/query * q:梦境关键字,如:黄金 需要...String BASE_URL = "http://v.juhe.cn/"; private static final int DEFAULT_TIMEOUT = 5; private Retrofit...retrofit; private JuHeService juheService; //构造方法私有 private HttpJuHeMethods() {...+Rxjava+MVP实践 MvpView public interface MvpView extends BaseView { //ListView的初始化 void setListItem
Retrofit官网 OkHttp: 也是Square 开源的网络请求库 RxJava:RxJava 在 GitHub 主页上的自我介绍是 "a library for composing asynchronous...RxJava + Retrofit + okHttp 已成为当前Android 网络请求最流行的方式。...一、添加依赖库 //RxJava compile 'io.reactivex:rxjava:1.1.3' //RxAndroid compile 'io.reactivex...:rxandroid:1.1.0' //retrofit compile 'com.squareup.retrofit2:retrofit:2.0.0' //retrofit依赖...:okhttp:3.2.0' //retrofit依赖RxJava compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0' 二、生成接口实例的管理类
RxJava + Retrofit 前言 本文基于RxJava、Retrofit的使用,若是对RxJava或Retrofit还不了解的简友可以先了解RxJava、Retrofit的用法再来看这篇文章。...) 使用 在了解了RxJava和Retrofit分别的用法后,RxJava、Retrofit的搭配使用也就不再话下了。...那Retrofit与RxJava结合是怎样使用的?下面就来说说这篇文章的重点。 RxJava + Retrofit完成网络请求 1、添加依赖。...前四个分别是RxJava、RxAndroid、Retrofit以及Gson的库,最后那个才是新加入的,RxJava + Retrofit的使用需要用到最后那个包。...compile 'io.reactivex:rxjava:x.y.z' compile 'io.reactivex:rxandroid:1.0.1' compile 'com.squareup.retrofit2
RxJava 异步、简洁,链式的写法使逻辑看起来更加清晰。...以上只是简单总结,文末附详细链接 本文也是以GitHubApi为例子 先加依赖 /*retrofit*/ compile 'com.squareup.retrofit2:retrofit:2.3.0...' compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0' compile 'com.squareup.retrofit2:converter-gson...:2.0.0-beta4' compile 'io.reactivex:rxandroid:1.1.0' compile 'com.squareup.okhttp3:logging-interceptor...使用详解 RxJava: RxJava图文详解,可以说是很全了。
接入RxJava 在Android中引入RxJava需要添加两个依赖,RxJava和RxAndroid implementation 'io.reactivex:rxjava:1.3.8' implementation...'io.reactivex:rxandroid:1.2.1' demo中的例子是用Retrofit来作为网络请求框架,所以还需要添加 Retrofit 的依赖 implementation 'com.squareup.retrofit2...:adapter-rxjava:2.0.0' 可能你是第一次用Retrofit还不了解它。...现在我们要用RxJava+Retrofit来修改getWeatherJava()这个方法。 代码对比--RxJava+Retrofit 没使用过Retrofit的话可能需要补充一下相应的知识点。...这就是Retrofit兼容RxJava的地方,它能直接生成一个Observable对象给RxJava作为链式调用的接收者,所以这也是为什么Retrofit+RxJava能让代码非常优雅的原因。
,这两年RxJava的流行让Retrofit着实火了一把,身为合格的Android开发人员要是对它不了解还真有点说不过去。...开篇 我是在去年的时候开始接触RxJava+Retrofit的,那时候还是RxJava1.x的版本,当时根据需求自己简单封装了一个网络库RxHttpUtils(https://github.com/lygttpod...近期正好又开了新项目,网络请求这块后台有些变化,之前的网络框架不能满足了,加上RxJava2都已经出来了,所以就有了基于RxJava2重新封装的想法,这几天对RxHttpUtils1.x(https:/...目录结果.png 介绍 原始RxJava+Retrofit的请求 正式开始之前我们先看看原始的Retrofit是怎么使用 ? ?...以上就是原始RxJava+Retrofit的请求方式,需要先构建出OKHttpClient,在实例化Retrofit最后才是create并且subscribe,中间还有线程切换的配置,大眼一看一个简单的请求写了这么多代码
优雅的解决Retrofit RxAndroid关联生命周期问题 Retrofit结合RxAndroid应该是史上最好用的网络请求框架了,在项目中只需要一段代码就可以完成网络请求以及回调处理,来看看google...Retrofit Rxandroid Adapter 为解决Retrofit关联的Activity、Fragment生命周期而设计。....with(this) // 关联生命周期 .subscribe(new YourObserver()); } } 二、配置 1、在Retrofit...Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://example.com/") // 添加适配器 .addCallAdapterFactory...maven { url 'https://jitpack.io' } } } dependencies { implementation 'com.github.raedev:retrofit-rxandroid-adapter