【发布时间】:2017-01-23 20:38:05
【问题描述】:
这是我的单身课程。
public class GetRetrofit {
static volatile Retrofit retrofit = null;
public static Retrofit getInstance() {
if (retrofit == null) {
synchronized (GetRetrofit.class) {
if (retrofit == null) {
OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
builder.readTimeout(30, TimeUnit.SECONDS);
builder.connectTimeout(30, TimeUnit.SECONDS);
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(interceptor);
// builder.addInterceptor(new UnauthorisedInterceptor(context));
OkHttpClient client = builder.build();
retrofit =
new Retrofit.Builder().baseUrl("DYNAMIC_URL")
.client(client).addConverterFactory(GsonConverterFactory.create()).build();
//addConverterFactory(SimpleXmlConverterFactory.create())
}
}
}
return retrofit;
}
}
我想更改动态基本网址。
例如:http://192.168.1.60:8888/property/Apiv1 需要在运行时更改此 url http://192.168.1.50:8008/inventory/Apiv1。
如何在运行时动态更改这两个 url。请帮帮我。
【问题讨论】:
标签: android singleton retrofit2