The approach of extending Application
is what I also have been recommending many times. It is recommended though to read this whole Stack Overflow question Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.
The approach of extending Application
is what I also have been recommending many times. It is recommended though to read this whole Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.
The approach of extending Application
is what I also have been recommending many times. It is recommended though to read this whole Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.
The approach of extending Application
is what I also have been recommending have been recommending many times. It is recommended though to read this whole Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.
The approach of extending Application
is what I also have been recommending many times. It is recommended though to read this whole Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.
The approach of extending Application
is what I also have been recommending many times. It is recommended though to read this whole Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.
The approach of extending Application
is what I also have been recommending many times. It is recommended though to read this whole Stack Overflow question.
As for your current code, I have one warning: It could theoretically create two objects if called in a multithreaded environment (although I doubt this will happen)
As for your current code, I feel that both these lines are a bit overkill:
((CustomApplication) this.getApplication()).initRestClient();
restClient = ((CustomApplication) this.getApplication()).getRestClient();
You could change your getRestClient
to:
public RestClient getRestClient() {
if (restClient == null) {
restClient = new RestAdapter.Builder().setEndpoint(BASE_URL).build().create(RestClient.class);
}
return restClient;
}
And then this line would be enough:
restClient = ((CustomApplication) this.getApplication()).getRestClient();
Although it would be better to just initialize the restClient
once by overriding the Application.onCreate() method.