How to dynamically pass different urls in retrofit2 android using Dagger
- In the
ApplicationClass
I'm passing one url and i use it in
ActLogin.java
- Now I want to pass
ActUpcomingEvents
another url different than
ActLogin.java
- How to achieve this
NetModule.java
@Module
public class NetModule {
String mBaseUrl;
Application mApplication;
// Constructor needs one parameter to instantiate.
public NetModule(String baseUrl, Application application) {
this.mBaseUrl = baseUrl;
this.mApplication = application;
}
// Dagger will only look for methods annotated with @Provides
@Provides
@Singleton
// Application reference must come from AppModule.class
SharedPreferences providesSharedPreferences(Application application) {
return PreferenceManager.getDefaultSharedPreferences(application);
}
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
int cacheSize = 10 * 1024 * 1024; // 10 MiB
Cache cache = new Cache(application.getCacheDir(), cacheSize);
return cache;
}
@Provides
@Singleton
Gson provideGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
return gsonBuilder.create();
}
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Cache cache) {
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.cache(cache);
client.addInterceptor(new RequestInterceptor(mApplication));
client.readTimeout(Keys.READ_TIMEOUT, TimeUnit.SECONDS);
client.connectTimeout(Keys.CONNECTION_TIMEOUT, TimeUnit.SECONDS);
client.writeTimeout(Keys.WRITE_TIMEOUT, TimeUnit.SECONDS);
return client.build();
}
@Provides @Named("auth")
@Singleton
Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(mBaseUrl)
.client(okHttpClient)
.build();
return retrofit;
}
}
AppModule.java
@Module
public class AppModule {
Application mApplication;
public AppModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
Application provideApplication() {
return mApplication;
}
}
SessionModule.java
@Module
public class SessionModule {
Application mApplication;
public SessionModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
// Application reference must come from AppModule.class
CaringSession providesCaringSession() {
return new CaringSession(mApplication);
}
}
NetComponent.java
@Singleton
@Component(modules = {AppModule.class,NetModule.class,SessionModule.class})
public interface NetComponent {
void inject(ActUpcomingEvents activity);
void inject(ActLogin activity);
}
ApplicationClass
public class CaringApp extends Application {
static CaringApp appInstance;
public static final String TAG = CaringApp.class.getSimpleName();
private NetComponent mNetComponent;
ANRWatchDog anrWatchDog = new ANRWatchDog(2000);
private RxBus bus;
private static CaringSession mSession;
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
mSession = new CaringSession(appInstance);
//Initialize the crashlytics
initCrashlytics();
//Initialize the watch dog
initAnrWatchDog();
//Initialize retrofit
retrofitInit();
//Rx Bus Init
}
public RxBus getBus() {
return bus;
}
private void initAnrWatchDog() {
anrWatchDog.setANRListener(new ANRWatchDog.ANRListener() {
@Override
public void onAppNotResponding(ANRError error) {
Log.e("ANR-Watchdog", "Detected Application Not Responding!");
// Some tools like ACRA are serializing the exception, so we must make sure the exception serializes correctly
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(error);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
Crashlytics.logException(new RuntimeException(error.getStackTrace().toString()));
Crashlytics.log(Log.ERROR, "ANR-LOG", error.getStackTrace().toString());
Log.i("ANR-Watchdog", "Error was successfully serialized");
throw error;
}
});
anrWatchDog.start();
}
/**************** Init ****************/
/** Init retrofit **/
private void retrofitInit() {
try{
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this))
.netModule(new NetModule(Keys.BASE_URL,this))
.sessionModule(new SessionModule(getAppInstance()))
.build();
}catch(Exception ex){
ex.printStackTrace();
}
}
/** Init crashlytics **/
private void initCrashlytics() {
Fabric.with(this, new Crashlytics());
}
/**************** Init ****************/
/**************** Getters ****************/
/** Net component **/
public NetComponent getNetComponent() {
return mNetComponent;
}
/** App Instance **/
public static CaringApp getAppInstance() {
if (appInstance == null) {
appInstance = new CaringApp();
}
return appInstance;
}
public static CaringSession getmSession() {
return mSession;
}
/**************** Getters ****************/
In my kotlinClass I am injecting like
class ActLogin : AppCompatActivity(), IntDataLogin {
@set:Inject var retrofit: Retrofit? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(application as CaringApp).netComponent.inject(this)
}
}
android retrofit2 dagger
add a comment |
- In the
ApplicationClass
I'm passing one url and i use it in
ActLogin.java
- Now I want to pass
ActUpcomingEvents
another url different than
ActLogin.java
- How to achieve this
NetModule.java
@Module
public class NetModule {
String mBaseUrl;
Application mApplication;
// Constructor needs one parameter to instantiate.
public NetModule(String baseUrl, Application application) {
this.mBaseUrl = baseUrl;
this.mApplication = application;
}
// Dagger will only look for methods annotated with @Provides
@Provides
@Singleton
// Application reference must come from AppModule.class
SharedPreferences providesSharedPreferences(Application application) {
return PreferenceManager.getDefaultSharedPreferences(application);
}
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
int cacheSize = 10 * 1024 * 1024; // 10 MiB
Cache cache = new Cache(application.getCacheDir(), cacheSize);
return cache;
}
@Provides
@Singleton
Gson provideGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
return gsonBuilder.create();
}
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Cache cache) {
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.cache(cache);
client.addInterceptor(new RequestInterceptor(mApplication));
client.readTimeout(Keys.READ_TIMEOUT, TimeUnit.SECONDS);
client.connectTimeout(Keys.CONNECTION_TIMEOUT, TimeUnit.SECONDS);
client.writeTimeout(Keys.WRITE_TIMEOUT, TimeUnit.SECONDS);
return client.build();
}
@Provides @Named("auth")
@Singleton
Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(mBaseUrl)
.client(okHttpClient)
.build();
return retrofit;
}
}
AppModule.java
@Module
public class AppModule {
Application mApplication;
public AppModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
Application provideApplication() {
return mApplication;
}
}
SessionModule.java
@Module
public class SessionModule {
Application mApplication;
public SessionModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
// Application reference must come from AppModule.class
CaringSession providesCaringSession() {
return new CaringSession(mApplication);
}
}
NetComponent.java
@Singleton
@Component(modules = {AppModule.class,NetModule.class,SessionModule.class})
public interface NetComponent {
void inject(ActUpcomingEvents activity);
void inject(ActLogin activity);
}
ApplicationClass
public class CaringApp extends Application {
static CaringApp appInstance;
public static final String TAG = CaringApp.class.getSimpleName();
private NetComponent mNetComponent;
ANRWatchDog anrWatchDog = new ANRWatchDog(2000);
private RxBus bus;
private static CaringSession mSession;
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
mSession = new CaringSession(appInstance);
//Initialize the crashlytics
initCrashlytics();
//Initialize the watch dog
initAnrWatchDog();
//Initialize retrofit
retrofitInit();
//Rx Bus Init
}
public RxBus getBus() {
return bus;
}
private void initAnrWatchDog() {
anrWatchDog.setANRListener(new ANRWatchDog.ANRListener() {
@Override
public void onAppNotResponding(ANRError error) {
Log.e("ANR-Watchdog", "Detected Application Not Responding!");
// Some tools like ACRA are serializing the exception, so we must make sure the exception serializes correctly
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(error);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
Crashlytics.logException(new RuntimeException(error.getStackTrace().toString()));
Crashlytics.log(Log.ERROR, "ANR-LOG", error.getStackTrace().toString());
Log.i("ANR-Watchdog", "Error was successfully serialized");
throw error;
}
});
anrWatchDog.start();
}
/**************** Init ****************/
/** Init retrofit **/
private void retrofitInit() {
try{
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this))
.netModule(new NetModule(Keys.BASE_URL,this))
.sessionModule(new SessionModule(getAppInstance()))
.build();
}catch(Exception ex){
ex.printStackTrace();
}
}
/** Init crashlytics **/
private void initCrashlytics() {
Fabric.with(this, new Crashlytics());
}
/**************** Init ****************/
/**************** Getters ****************/
/** Net component **/
public NetComponent getNetComponent() {
return mNetComponent;
}
/** App Instance **/
public static CaringApp getAppInstance() {
if (appInstance == null) {
appInstance = new CaringApp();
}
return appInstance;
}
public static CaringSession getmSession() {
return mSession;
}
/**************** Getters ****************/
In my kotlinClass I am injecting like
class ActLogin : AppCompatActivity(), IntDataLogin {
@set:Inject var retrofit: Retrofit? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(application as CaringApp).netComponent.inject(this)
}
}
android retrofit2 dagger
add a comment |
- In the
ApplicationClass
I'm passing one url and i use it in
ActLogin.java
- Now I want to pass
ActUpcomingEvents
another url different than
ActLogin.java
- How to achieve this
NetModule.java
@Module
public class NetModule {
String mBaseUrl;
Application mApplication;
// Constructor needs one parameter to instantiate.
public NetModule(String baseUrl, Application application) {
this.mBaseUrl = baseUrl;
this.mApplication = application;
}
// Dagger will only look for methods annotated with @Provides
@Provides
@Singleton
// Application reference must come from AppModule.class
SharedPreferences providesSharedPreferences(Application application) {
return PreferenceManager.getDefaultSharedPreferences(application);
}
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
int cacheSize = 10 * 1024 * 1024; // 10 MiB
Cache cache = new Cache(application.getCacheDir(), cacheSize);
return cache;
}
@Provides
@Singleton
Gson provideGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
return gsonBuilder.create();
}
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Cache cache) {
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.cache(cache);
client.addInterceptor(new RequestInterceptor(mApplication));
client.readTimeout(Keys.READ_TIMEOUT, TimeUnit.SECONDS);
client.connectTimeout(Keys.CONNECTION_TIMEOUT, TimeUnit.SECONDS);
client.writeTimeout(Keys.WRITE_TIMEOUT, TimeUnit.SECONDS);
return client.build();
}
@Provides @Named("auth")
@Singleton
Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(mBaseUrl)
.client(okHttpClient)
.build();
return retrofit;
}
}
AppModule.java
@Module
public class AppModule {
Application mApplication;
public AppModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
Application provideApplication() {
return mApplication;
}
}
SessionModule.java
@Module
public class SessionModule {
Application mApplication;
public SessionModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
// Application reference must come from AppModule.class
CaringSession providesCaringSession() {
return new CaringSession(mApplication);
}
}
NetComponent.java
@Singleton
@Component(modules = {AppModule.class,NetModule.class,SessionModule.class})
public interface NetComponent {
void inject(ActUpcomingEvents activity);
void inject(ActLogin activity);
}
ApplicationClass
public class CaringApp extends Application {
static CaringApp appInstance;
public static final String TAG = CaringApp.class.getSimpleName();
private NetComponent mNetComponent;
ANRWatchDog anrWatchDog = new ANRWatchDog(2000);
private RxBus bus;
private static CaringSession mSession;
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
mSession = new CaringSession(appInstance);
//Initialize the crashlytics
initCrashlytics();
//Initialize the watch dog
initAnrWatchDog();
//Initialize retrofit
retrofitInit();
//Rx Bus Init
}
public RxBus getBus() {
return bus;
}
private void initAnrWatchDog() {
anrWatchDog.setANRListener(new ANRWatchDog.ANRListener() {
@Override
public void onAppNotResponding(ANRError error) {
Log.e("ANR-Watchdog", "Detected Application Not Responding!");
// Some tools like ACRA are serializing the exception, so we must make sure the exception serializes correctly
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(error);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
Crashlytics.logException(new RuntimeException(error.getStackTrace().toString()));
Crashlytics.log(Log.ERROR, "ANR-LOG", error.getStackTrace().toString());
Log.i("ANR-Watchdog", "Error was successfully serialized");
throw error;
}
});
anrWatchDog.start();
}
/**************** Init ****************/
/** Init retrofit **/
private void retrofitInit() {
try{
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this))
.netModule(new NetModule(Keys.BASE_URL,this))
.sessionModule(new SessionModule(getAppInstance()))
.build();
}catch(Exception ex){
ex.printStackTrace();
}
}
/** Init crashlytics **/
private void initCrashlytics() {
Fabric.with(this, new Crashlytics());
}
/**************** Init ****************/
/**************** Getters ****************/
/** Net component **/
public NetComponent getNetComponent() {
return mNetComponent;
}
/** App Instance **/
public static CaringApp getAppInstance() {
if (appInstance == null) {
appInstance = new CaringApp();
}
return appInstance;
}
public static CaringSession getmSession() {
return mSession;
}
/**************** Getters ****************/
In my kotlinClass I am injecting like
class ActLogin : AppCompatActivity(), IntDataLogin {
@set:Inject var retrofit: Retrofit? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(application as CaringApp).netComponent.inject(this)
}
}
android retrofit2 dagger
- In the
ApplicationClass
I'm passing one url and i use it in
ActLogin.java
- Now I want to pass
ActUpcomingEvents
another url different than
ActLogin.java
- How to achieve this
NetModule.java
@Module
public class NetModule {
String mBaseUrl;
Application mApplication;
// Constructor needs one parameter to instantiate.
public NetModule(String baseUrl, Application application) {
this.mBaseUrl = baseUrl;
this.mApplication = application;
}
// Dagger will only look for methods annotated with @Provides
@Provides
@Singleton
// Application reference must come from AppModule.class
SharedPreferences providesSharedPreferences(Application application) {
return PreferenceManager.getDefaultSharedPreferences(application);
}
@Provides
@Singleton
Cache provideOkHttpCache(Application application) {
int cacheSize = 10 * 1024 * 1024; // 10 MiB
Cache cache = new Cache(application.getCacheDir(), cacheSize);
return cache;
}
@Provides
@Singleton
Gson provideGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
return gsonBuilder.create();
}
@Provides
@Singleton
OkHttpClient provideOkHttpClient(Cache cache) {
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.cache(cache);
client.addInterceptor(new RequestInterceptor(mApplication));
client.readTimeout(Keys.READ_TIMEOUT, TimeUnit.SECONDS);
client.connectTimeout(Keys.CONNECTION_TIMEOUT, TimeUnit.SECONDS);
client.writeTimeout(Keys.WRITE_TIMEOUT, TimeUnit.SECONDS);
return client.build();
}
@Provides @Named("auth")
@Singleton
Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(mBaseUrl)
.client(okHttpClient)
.build();
return retrofit;
}
}
AppModule.java
@Module
public class AppModule {
Application mApplication;
public AppModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
Application provideApplication() {
return mApplication;
}
}
SessionModule.java
@Module
public class SessionModule {
Application mApplication;
public SessionModule(Application mApplication) {
this.mApplication = mApplication;
}
@Provides
@Singleton
// Application reference must come from AppModule.class
CaringSession providesCaringSession() {
return new CaringSession(mApplication);
}
}
NetComponent.java
@Singleton
@Component(modules = {AppModule.class,NetModule.class,SessionModule.class})
public interface NetComponent {
void inject(ActUpcomingEvents activity);
void inject(ActLogin activity);
}
ApplicationClass
public class CaringApp extends Application {
static CaringApp appInstance;
public static final String TAG = CaringApp.class.getSimpleName();
private NetComponent mNetComponent;
ANRWatchDog anrWatchDog = new ANRWatchDog(2000);
private RxBus bus;
private static CaringSession mSession;
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
mSession = new CaringSession(appInstance);
//Initialize the crashlytics
initCrashlytics();
//Initialize the watch dog
initAnrWatchDog();
//Initialize retrofit
retrofitInit();
//Rx Bus Init
}
public RxBus getBus() {
return bus;
}
private void initAnrWatchDog() {
anrWatchDog.setANRListener(new ANRWatchDog.ANRListener() {
@Override
public void onAppNotResponding(ANRError error) {
Log.e("ANR-Watchdog", "Detected Application Not Responding!");
// Some tools like ACRA are serializing the exception, so we must make sure the exception serializes correctly
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(error);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
Crashlytics.logException(new RuntimeException(error.getStackTrace().toString()));
Crashlytics.log(Log.ERROR, "ANR-LOG", error.getStackTrace().toString());
Log.i("ANR-Watchdog", "Error was successfully serialized");
throw error;
}
});
anrWatchDog.start();
}
/**************** Init ****************/
/** Init retrofit **/
private void retrofitInit() {
try{
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this))
.netModule(new NetModule(Keys.BASE_URL,this))
.sessionModule(new SessionModule(getAppInstance()))
.build();
}catch(Exception ex){
ex.printStackTrace();
}
}
/** Init crashlytics **/
private void initCrashlytics() {
Fabric.with(this, new Crashlytics());
}
/**************** Init ****************/
/**************** Getters ****************/
/** Net component **/
public NetComponent getNetComponent() {
return mNetComponent;
}
/** App Instance **/
public static CaringApp getAppInstance() {
if (appInstance == null) {
appInstance = new CaringApp();
}
return appInstance;
}
public static CaringSession getmSession() {
return mSession;
}
/**************** Getters ****************/
In my kotlinClass I am injecting like
class ActLogin : AppCompatActivity(), IntDataLogin {
@set:Inject var retrofit: Retrofit? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(application as CaringApp).netComponent.inject(this)
}
}
android retrofit2 dagger
android retrofit2 dagger
asked 2 days ago
DevrathDevrath
22.3k38132186
22.3k38132186
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you mean, you have another base url. you can do something like this;
public interface YourAPIInterface {
@GET
Call<POJO> doAllItems(@Url String url);
}
@Url
annotation on a parameter to allow specifying a full host name dynamically. Then you can call it the normal way in Refrofit
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54252764%2fhow-to-dynamically-pass-different-urls-in-retrofit2-android-using-dagger%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you mean, you have another base url. you can do something like this;
public interface YourAPIInterface {
@GET
Call<POJO> doAllItems(@Url String url);
}
@Url
annotation on a parameter to allow specifying a full host name dynamically. Then you can call it the normal way in Refrofit
add a comment |
If you mean, you have another base url. you can do something like this;
public interface YourAPIInterface {
@GET
Call<POJO> doAllItems(@Url String url);
}
@Url
annotation on a parameter to allow specifying a full host name dynamically. Then you can call it the normal way in Refrofit
add a comment |
If you mean, you have another base url. you can do something like this;
public interface YourAPIInterface {
@GET
Call<POJO> doAllItems(@Url String url);
}
@Url
annotation on a parameter to allow specifying a full host name dynamically. Then you can call it the normal way in Refrofit
If you mean, you have another base url. you can do something like this;
public interface YourAPIInterface {
@GET
Call<POJO> doAllItems(@Url String url);
}
@Url
annotation on a parameter to allow specifying a full host name dynamically. Then you can call it the normal way in Refrofit
answered 2 days ago
Nanda ZNanda Z
379
379
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54252764%2fhow-to-dynamically-pass-different-urls-in-retrofit2-android-using-dagger%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown