private Retrofit retrofit;
private static RetrofitUtils retrofitUtils;
private RetrofitUtils() {
doretrofit();
}
//单例模式
public static RetrofitUtils getInstense() {
if (retrofitUtils == null) {
synchronized (RetrofitUtils.class) {
if (retrofitUtils == null) {
retrofitUtils = new RetrofitUtils();
}
}
}
return retrofitUtils;
}
//Retrofit+Rxjava
private void doretrofit() {
//创建构造模式
retrofit = new Retrofit.Builder()
.baseUrl("http://mobile.bwstudent.com/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
public <T> T create(Class<T> service) {
return retrofit.create(service);
}
Retrofit+Rxjava封装单例
猜你喜欢
转载自blog.csdn.net/qq_42809175/article/details/88934478
今日推荐
周排行