RxJavaSamples-master | # 像OkHttp一样使用
kandi X-RAY | RxJavaSamples-master Summary
kandi X-RAY | RxJavaSamples-master Summary
RxJavaSamples-master is a Java library. RxJavaSamples-master has no bugs, it has no vulnerabilities, it has build file available and it has low support. You can download it from GitHub.
#像OkHttp一样使用 当然实际的项目开发中,不可能给我们时间慢慢去适应、去学习,要考虑技术风险和学习成本、团队共用。所以我才觉得Retrofit这一点好贴心,基于OkHttp实现,也就是说我当我遇到我不知道该怎么实现的功能的时候,可以无缝切换到OkHttp上面实现需求。 看看下面的代码,同样申明一个请求call,同样的异步 call.enqueue,同样的回调Callback,甚至连 mDatas = new Gson().fromJson(res, new TypeToken>Gson解析都是从前的味道。但是我们已经开始在使用Retrofit了,不知不觉,潜移默化中已经前进了一小步。. 这里的 @GET("search")表示使用get请求,同时search是get命令路径的一部分 ##Path 当然,你也可以把他写到参数里面,Like This. 直接使用 mDatas = response.body();就可以获取,当然请求的函数泛型也要改写. 省去了在回调函数new Gson的干扰,代码变得跟简洁。 当然,这里使用的是Gson,如果你需要JackSon,FastJson选择合适的解析器传递进去就行了。 如果,你需要自定义解析规则,也是没问题的,这需要自己去实现,但是这不是我们今天要说的重点,放到后面再写一个这种例子。 总之---使用了解析器,让我们的代码可读性变得更好,代码也更简洁。. 和解析器一样,适配器也就是加了一句 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())//添加适配器 连接 代码虽然简洁,作用巨大,注意现在我们已经不用Call来做请求了,我们使用Observable,这直接就可以利用RxJava操作。. 3.链式调用,整个逻辑清晰明了 但是注意一点: 对API调用了 observeOn(MainThread) 之后,线程会跑在主线程上,包括 onComplete 也是, unsubscribe 也在主线程,然后如果这时候调用 call.cancel 会导致 NetworkOnMainThreadException ,所以一定要在 retrofit 的API调用.subscribeOn(io).observeOn(MainThread) 之后加一句 unsubscribeOn(io). 还可以通过自定义 HttpLoggingInterceptor logger = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger()个性化打造自己的网络数据请求打印。 #组装监听器---监听Response下行数据 把拦截器,进一步升华,比如下载数据的时候,拦截下Response,读取里面的信息,然后再传输给下一层,不就可以实现监听下行数据么。 先实现一个监听器. 查看Log #组装监听器2---获取Request上传进度 上传和下行,同理,实现一个具备拦截能力的Request即可 太快了,模拟器里面没有大一点的图片,本来是有进度条显示,看下日志吧.
#像OkHttp一样使用 当然实际的项目开发中,不可能给我们时间慢慢去适应、去学习,要考虑技术风险和学习成本、团队共用。所以我才觉得Retrofit这一点好贴心,基于OkHttp实现,也就是说我当我遇到我不知道该怎么实现的功能的时候,可以无缝切换到OkHttp上面实现需求。 看看下面的代码,同样申明一个请求call,同样的异步 call.enqueue,同样的回调Callback,甚至连 mDatas = new Gson().fromJson(res, new TypeToken>Gson解析都是从前的味道。但是我们已经开始在使用Retrofit了,不知不觉,潜移默化中已经前进了一小步。. 这里的 @GET("search")表示使用get请求,同时search是get命令路径的一部分 ##Path 当然,你也可以把他写到参数里面,Like This. 直接使用 mDatas = response.body();就可以获取,当然请求的函数泛型也要改写. 省去了在回调函数new Gson的干扰,代码变得跟简洁。 当然,这里使用的是Gson,如果你需要JackSon,FastJson选择合适的解析器传递进去就行了。 如果,你需要自定义解析规则,也是没问题的,这需要自己去实现,但是这不是我们今天要说的重点,放到后面再写一个这种例子。 总之---使用了解析器,让我们的代码可读性变得更好,代码也更简洁。. 和解析器一样,适配器也就是加了一句 .addCallAdapterFactory(RxJavaCallAdapterFactory.create())//添加适配器 连接 代码虽然简洁,作用巨大,注意现在我们已经不用Call来做请求了,我们使用Observable,这直接就可以利用RxJava操作。. 3.链式调用,整个逻辑清晰明了 但是注意一点: 对API调用了 observeOn(MainThread) 之后,线程会跑在主线程上,包括 onComplete 也是, unsubscribe 也在主线程,然后如果这时候调用 call.cancel 会导致 NetworkOnMainThreadException ,所以一定要在 retrofit 的API调用.subscribeOn(io).observeOn(MainThread) 之后加一句 unsubscribeOn(io). 还可以通过自定义 HttpLoggingInterceptor logger = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger()个性化打造自己的网络数据请求打印。 #组装监听器---监听Response下行数据 把拦截器,进一步升华,比如下载数据的时候,拦截下Response,读取里面的信息,然后再传输给下一层,不就可以实现监听下行数据么。 先实现一个监听器. 查看Log #组装监听器2---获取Request上传进度 上传和下行,同理,实现一个具备拦截能力的Request即可 太快了,模拟器里面没有大一点的图片,本来是有进度条显示,看下日志吧.
Support
Quality
Security
License
Reuse
Support
RxJavaSamples-master has a low active ecosystem.
It has 1 star(s) with 2 fork(s). There are 1 watchers for this library.
It had no major release in the last 6 months.
RxJavaSamples-master has no issues reported. There are no pull requests.
It has a neutral sentiment in the developer community.
The latest version of RxJavaSamples-master is current.
Quality
RxJavaSamples-master has no bugs reported.
Security
RxJavaSamples-master has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
License
RxJavaSamples-master does not have a standard license declared.
Check the repository for any license declaration and review the terms closely.
Without a license, all rights are reserved, and you cannot use the library in your applications.
Reuse
RxJavaSamples-master releases are not available. You will need to build from source code and install.
Build file is available. You can build the component from source.
Installation instructions are not available. Examples and code snippets are available.
Top functions reviewed by kandi - BETA
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of RxJavaSamples-master
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of RxJavaSamples-master
RxJavaSamples-master Key Features
No Key Features are available at this moment for RxJavaSamples-master.
RxJavaSamples-master Examples and Code Snippets
No Code Snippets are available at this moment for RxJavaSamples-master.
Community Discussions
No Community Discussions are available at this moment for RxJavaSamples-master.Refer to stack overflow page for discussions.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RxJavaSamples-master
You can download it from GitHub.
You can use RxJavaSamples-master like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the RxJavaSamples-master component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
You can use RxJavaSamples-master like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the RxJavaSamples-master component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
For any new features, suggestions and bugs create an issue on GitHub.
If you have any questions check and ask questions on community page Stack Overflow .
Find more information at:
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page