我相信这对您来说是一个非常简单的问题,但我无法解决。
我的应用程序从AUTHpage开始,然后转到另一个页面-DOMAIN,我需要在其中输入一些参数,然后返回AUTHpage。第一次调用AUTHpage时,确定DOMAIN =“ game.com”,当我回到AUTHpage时,我看到DOMAIN名称已更改为=“ play.com”,但是AppModule中的baseUrl链接未更改,因为AppModule没有多次打电话。怎么做?
public class AppModule {
@Singleton
@Provides
public Retrofit provideRetrofit(Context context, GsonConverterFactory gsonConverterFactory RxJavaCallAdapterFactory rxJavaCallAdapterFactory, OkHttpClient okHttpClient){
System.out.println("domainNameAuth in AppModule " + DomainActivity.DOMAIN);
return new Retrofit.Builder()
.baseUrl("https://api." + DomainActivity.DOMAIN +"/")
.addConverterFactory(gsonConverterFactory)
.addCallAdapterFactory(rxJavaCallAdapterFactory)
.client(okHttpClient)
.build();
}
}
@Singleton @Component(modules = AppModule.class)
public interface AppComponent {
void inject(AUTHpage activity);
}
公共类AUTHpage扩展了BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auth);
Application.getComponent(this).inject(this);
initViews();
}
}
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
mApplicationComponent = createComponent();
}
private AppComponent createComponent() {
return DaggerAppComponent.builder()
.appModule(new AppModule(this))
.build();
}
}