title: Android okhttp Async progressdialog
body: <p>I want to add progressdialog into okhttp (asynchronous, not AsyncTask) </p>
  
  <p>but i got this error:</p>
  
  <blockquote>
    <p>Error: Can't create handler inside thread that has not called
    Looper.prepare()</p>
  </blockquote>
  
  <p>How to fix it in a proper way? I want to be sure that is the best way to do this. </p>
  
  <pre><code>  client.newCall(request).enqueue(new Callback() {
          @Override
          public void onFailure(Call call, IOException e) {
              Log.d("TAG_response", " brak neta lub polaczenia z serwerem ");
              e.printStackTrace();
          }
  
          @Override
          public void onResponse(Call call, Response response) throws IOException {
                   progress = ProgressDialog.show(SignUp.this, "dialog title",
                      "dialog message", true);
              try {
                  Log.d("TAGx", response.body().string());
                  if (response.isSuccessful()) {
                      Headers responseHeaders = response.headers();
                      for (int i = 0, size = responseHeaders.size(); i &lt; size; i++) {
                          //System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
                          Log.d("TAG2", responseHeaders.name(i));
                          Log.d("TAG3", responseHeaders.value(i));
  
                      }
                      Log.d("TAG", response.body().string());
                      progress.dismiss();
                      main_activity();
                  }
                  else{
                      progress.dismiss();
  
                      alertUserAboutError();
                  }
              }
              catch (IOException e){
                  Log.d("TAG", "error");
              }
  
          }
  
      });
  </code></pre>