retrofit rxjava android 封装 使用
本人使用 github 现成封装 modules rxretrofitlibrary
一步步封装 移步 http://blog.csdn.net/wzgiceman/article/details/51939574
专栏 移步 http://blog.csdn.net/column/details/13297.html
该博主 三个 版本的 gitbub 成果:
https://github.com/wzgiceman/RxjavaRetrofitDemo-string-master
https://github.com/wzgiceman/RxjavaRetrofitDemo-master
https://github.com/wzgiceman/Rx-Retrofit
本人使用 RxjavaRetrofitDemo-string-master modules
该 网络请求 包含 缓存功能,包含 重试功能
public class IteyeBlogsApi extends BaseApi { public IteyeBlogsApi(){ setBaseUrl("http://www.iteye.com/"); } @Override public Observable getObservable(Retrofit retrofit) { IteyeGetBlogsService api= retrofit.create(IteyeGetBlogsService.class); return api.getAllBlogs(); } }
public interface IteyeGetBlogsService { @GET("blogs") Observable<String> getAllBlogs(); }
myApi = new IteyeBlogsApi();
manager = new HttpManager(this, this);
case R.id.btn_rx_text_iteye: Log.i("baoyou","myApi ===== start"); manager.doHttpDeal(myApi); break;
结果 测试
2.测试 一个 本地rest 服务
public interface LocalUserRestService { @GET("user/list") Observable<String> getAllUsers(); }
public class LocalUserRestApi extends BaseApi { public LocalUserRestApi(){ setBaseUrl("http://192.168.50.61:8081/rest/rest/"); } @Override public Observable getObservable(Retrofit retrofit) { LocalUserRestService api= retrofit.create(LocalUserRestService.class); return api.getAllUsers(); } }
Log.i("baoyou","userRestApi ===== new start"); userRestApi = new LocalUserRestApi(); Log.i("baoyou","userRestApi ===== new start");
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_rx_text_rest_user: Log.i("baoyou","userRestApi ===== start"); manager.doHttpDeal(userRestApi); Log.i("baoyou","userRestApi ===== end"); break;
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信捐助,加入it技术扣扣群),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
霸气的名字 2020-06-23
smaillift 2020-02-17
霸气的名字 2020-02-15
RikkaTheWorld 2019-12-08
TOmyhonour 2019-11-08
齐天大圣数据候 2019-10-31
kcstrong 2019-10-19
冰川孤辰 2019-09-08
kangtingting0 2019-09-07
俊光 2018-08-10
俊光 2019-07-30
xzw 2019-07-01
smaillift 2019-07-01
javashu0 2019-07-01
needh 2019-06-30
kcstrong 2019-06-28
qjbagu 2016-04-05
霸气的名字 2019-06-27