title: Retrofit2 singleton Instance
body: <p>I am trying to create singleton instance for Retrofit2 which works fine. But as soon as I want to dynamic header I am unable to do so.</p>
  
  <pre><code>public class ApiManager {
  
  
      public final static String BASE_URL = "URL";
  
  
  
      private static ApiManager instance =null;
      private ApiModule apiModule;
  
      public interface ApiModule {
  
  
          @GET("exists")
          Call&lt;ServerStatus&gt; checkExistsTeamName(@Path("teamName") String teamName);
  
  
      }
  
  
      private ApiManager(){
          final TimeZone tz = TimeZone.getDefault();
          OkHttpClient client = new OkHttpClient();
          HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
          interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
          try {
              client.interceptors().add(new Interceptor() {
                  @Override
                  public com.squareup.okhttp.Response intercept(Interceptor.Chain chain) throws
                          IOException {
  
                      Request original = chain.request();
                      Request request = original.newBuilder()
                              .header("X-API-Version", "1")
                              .header("X-USER-TIMEZONE", tz.getID())
                              .method(original.method(), original.body())
                              .build();
  
  
                      return chain.proceed(request);
  
                  }
              });
          }catch (Exception e){
  
          }
          client.interceptors().add(interceptor);
  
          Retrofit retrofit = new Retrofit.Builder()
                  .baseUrl(BASE_URL)
                  .addConverterFactory(GsonConverterFactory.create())
                  .client(client)
                  .build();
  
          apiModule = retrofit.create(ApiModule.class);
      }
  
  
  
  
  
      public static ApiManager getInstance() {
          if(instance == null) {
              instance = new ApiManager();
          }
          return instance;
      }
  
  
  
  
      public ApiModule getService() {
          return apiModule;
      }
  
      public ApiModule getService(String token){
          return apiModule;
      }
  
  
  
  
  }
  </code></pre>
  
  <p>And in the other activity I can get call to retrofit as.</p>
  
  <p>ApiManager apiManager = ApiManager.getInstance();
  apiManager.getService().checkExistsTeamName("parameters")</p>
  
  <p>Which works fine here But want if I want to add extra additional dynamic headers how should I do it?? I am stuck here</p>