title: Retrofit 2 enqueue method running 2 times
body: <p>I am new to Retrofit Library. I am working on an app in which I've to make multiple API calls, but this problem sticks me when I tried to make my first API Call...</p>
  
  <p>I am facing the issue that whenever I used to call retrofit's Asynchronous call method then the functionality inside onResponse method is running 2 times...</p>
  
  <p>This is my code when I am calling the API call asynchronously...</p>
  
  <pre><code>final ApiModule apiService = ApiServiceGenerator.createService(ApiModule.class);
  Call &lt;ConfigResponse&gt; call = apiService.getConfig();
  
  call.enqueue(new Callback&lt;ConfigResponse&gt;() {
    @Override
    public void onResponse(Call&lt;ConfigResponse&gt; call, Response&lt;ConfigResponse&gt; response) {
      try {
          if (response.isSuccessful()) {
              Log.e("MyTag", "This is running");
          }
      } catch(Exception e) {
          e.printStackTrace();
      }
    }
  
    @Override
    public void onFailure(Call&lt;ConfigResponse&gt; call, Throwable t) {
      e.printStackTrace();
    }
  });
  </code></pre>
  
  <p>As soon as I run the App on the device and when I see my android studio's logger, its is showing me the log message as - </p>
  
  <pre><code>E/MyTag: This is running
  E/MyTag: This is running
  </code></pre>
  
  <p>It seems here that its running for 2 times..!!</p>
  
  <p>I cannot understand that why is it running 2 times.
  Please help me out with this...</p>
  
  <p>Just for more help...
  I've implemented my code like this.</p>
  
  <p>ApiModule Interface (where I defined my API Call URLs)</p>
  
  <pre><code>public abstract interface ApiModule {
  
    @GET("config")
    Call&lt;ConfigResponse&gt; getConfig();
  
  }
  </code></pre>
  
  <p>ApiServiceGenerator goes like this -</p>
  
  <pre><code>public class ApiServiceGenerator {
  
  public static final String API_BASE_URL = "https://www.example.com/";
  private static OkHttpClient httpClient = new OkHttpClient.Builder()
          .addInterceptor(new Interceptor() {
              @Override
              public okhttp3.Response intercept(Chain chain) throws IOException {
                  Request newRequest = chain.request().newBuilder().addHeader("App-Secret", "some-secret-key").build();
                  return chain.proceed(newRequest);
              }
          })
          .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) // Just For logging
          .readTimeout(60, TimeUnit.SECONDS)
          .connectTimeout(60, TimeUnit.SECONDS)
          .build();
  
  Gson gson = new GsonBuilder()
          .registerTypeAdapterFactory(new ArrayAdapterFactory())
          .create();
  
  private static Retrofit.Builder builder =
          new Retrofit.Builder()
                  .baseUrl(API_BASE_URL)
                  .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create()));
  
  public static &lt;S&gt; S createService(Class&lt;S&gt; serviceClass) {
      Retrofit retrofit = builder.client(httpClient).build();
      return retrofit.create(serviceClass);
  }
  
  public static Retrofit retrofit() { // For Error Handing when non-OK response is received from Server
      OkHttpClient httpClient = new OkHttpClient.Builder().build();
      OkHttpClient client = httpClient;
      return builder.client(client).build();
  }
  }
  </code></pre>