retrofit 响应时间_Android使用RxJava+Retrofit2+Okhttp+MVP练习的APP

本文介绍了如何在Android应用中使用RxJava、Retrofit2、Okhttp和MVP架构进行网络请求及缓存管理。详细步骤包括导入依赖、创建API接口、实现缓存接口、构建Retrofit抽象类和HttpData管理类,展示了如何在实际项目中运用这些技术栈。
摘要由CSDN通过智能技术生成

Android使用RxJava+Retrofit2+Okhttp+MVP练习的APP

项目截图

这是我的目录结构

五步使用RxJava+Retrofit2+Okhttp+RxCache

第一步:导包

compile 'io.reactivex:rxjava:1.1.8'

compile 'io.reactivex:rxandroid:1.2.1'

compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'

compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'

compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'

compile 'com.github.VictorAlbertos.RxCache:core:1.4.6'

第二步:新建API接口

public interface GanHuoService {

@GET("data/{type}/{number}/{page}")

Observable getDataResults(

@Path("type") String type,

@Path("number") int number,

@Path("page") int page

);

}

第三步:新建缓存接口

/**

* 缓存API接口

*

* @LifeCache设置缓存过期时间. 如果没有设置@LifeCache , 数据将被永久缓存理除非你使用了 EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup .

* EvictProvider可以明确地清理清理所有缓存数据.

* EvictDynamicKey可以明确地清理指定的数据 DynamicKey.

* EvictDynamicKeyGroup 允许明确地清理一组特定的数据. DynamicKeyGroup.

* DynamicKey驱逐与一个特定的键使用EvictDynamicKey相关的数据。比如分页,排序或筛选要求

* DynamicKeyGroup。驱逐一组与key关联的数据,使用EvictDynamicKeyGroup。比如分页,排序或筛选要求

*/

public interface CacheProviders {

//缓存时间 1天

@LifeCache(duration = 7, timeUnit = TimeUnit.DAYS)

Observable>> getHomeTypes(Observable observable, DynamicKey userName, EvictDynamicKey evictDynamicKey);

}

第四步:新建retrofit抽象类

public abstract class RetrofitUtils {

private static Retrofit mRetrofit;

private static OkHt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值