I would like to inject resource and use it in the constructor of singleton class with roboguice injection. Below is an example that shows what I need but injected field is null in the constructor. I was reading something about providers and overthink another special class for getting url but I am not so sure if it's convenient solution. Code below:
@Singleton
public class ProductService implements IProductService {
@InjectResource(R.string.server_url)
private String serverBaseUrl;
IProductAPI productAPI;
public ProductService() {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(serverBaseUrl)
.build();
productAPI = restAdapter.create(IProductAPI.class);
}
public ProductDTO retrieveProductByEan(String productEan) throws RetrofitError {
return productAPI.getProductByEan(productEan);
}
}