title: Return variable from onResponse Retrofit
body: <p>I do a API call to a webserver and I get the ID back in the method onResponse.</p>
  
  <p>Now I want to save this ID and return this id in the return of the method doLogin. How can I get that variable ID in the return statement?</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class LoginController {
  
      public static String doLogin(String loginMail, String loginPassword) {
  
          //Logging Retrofit
          final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
          interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
          OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
  
          Retrofit retrofit = new Retrofit.Builder()
                  .baseUrl("###URLTOAPICALL###")
                  .client(client)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
  
          APIService service = retrofit.create(APIService.class);
          Call&lt;JsonElement&gt; call = service.doLogin(loginMail, loginPassword);
  
          call.enqueue(new Callback&lt;JsonElement&gt;() {
              @Override
              public void onResponse(Call&lt;JsonElement&gt; call, Response&lt;JsonElement&gt; response) {
  
                  if (response != null) {
                      JSONObject obj = null;
  
                      try {
                          obj = new JSONObject(response.body().toString());
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                      JSONObject setup = null;
                      try {
                          setup = obj.getJSONObject("setup");
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                      if(setup != null) {
                          try {
                              Setup stp = new Setup();
                              stp.setUserId(setup.getInt("id"));
  
                              //I WANT HERE TO SAVE MY ID
  
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
  
  
                      }
                  }
              }
  
              @Override
              public void onFailure(Call&lt;JsonElement&gt; call, Throwable t) {
                  Log.v("ERROR", t+"");
              }
  
  
          });
  
          return "I WANT RETURN THAT ID HERE";
      }
  }
  </code></pre>