title: How to do async OkHttp request in another class and then callback to activity
body: <p>I want to move my OkHttp async request to a separate class as I use it multiple times in multiple activities in my application. Is this possible? I've read a lot about it but can't find a solution for me.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public void mainActivityMethod(String JSONData) {
       // Handle JSONData string
  }
  </code></pre>
  
  <p>MyClass.java</p>
  
  <pre><code>public void doRequest() {
  
      OkHttpClient okHttpClient = new OkHttpClient();
      Request request = new Request.Builder()
              .url(url)
              .build();
  
      Call call = okHttpClient.newCall(request);
  
      call.enqueue(new Callback() {
          @Override
          public void onFailure(Request request, IOException e) {
              e.printStackTrace();
          }
  
          @Override
          public void onResponse(final Response response) throws IOException {
              if (response.isSuccessful()) {
  
                  // Fetch request data
                  String JSONData = response.body().string();
  
                  mainActivityMethod(JSONData);
  
              }
          }
      });
  
  }
  </code></pre>