Answer the question
In order to leave comments, you need to log in
Question about Retrofit - why is it implemented like that?
Here is an example of a simple class for working with Retrofit:
public class NetworkService {
private static NetworkService mInstance;
private static final String BASE_URL = "https://jsonplaceholder.typicode.com";
private Retrofit mRetrofit;
private NetworkService() {
mRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static NetworkService getInstance() {
if (mInstance == null) {
mInstance = new NetworkService();
}
return mInstance;
}
public JSONPlaceHolderApi getJSONApi() {
return mRetrofit.create(JSONPlaceHolderApi.class);
}
}
create(JSONPlaceHolderApi.class)
in the method getJSONApi()
? Why create(JSONPlaceHolderApi.class)
is it not called once (for example, in the constructor), but each time it will be called when calling getJSONApi ()? JSONPlaceHolderApi
? Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question