Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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.

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

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.

Source Link
Simon Forsberg
  • 59.7k
  • 9
  • 157
  • 311

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.

lang-java

AltStyle によって変換されたページ (->オリジナル) /