title: Wait for thread, get its result, show progressbar in the process and do not block UI Thread
body: <p>So as the title probably suggests - I've done a lot of research on the topic, but I am still confused and unable of achieving what I want.</p>
  
  <p>In very simplified scenario, I have a LoginActivity in which is method <code>boolean validateUserInput(String mail, String password)</code> and I want to do the check input in the separate thread. I suppose I will extend it in the future to do the log-in itself as well (http request). Naturally I would like to get boolean value if the operation was successful or not - and in the process of operation I want to show progressbar dialog.</p>
  
  <p>Make a thread, run the code, return its result, show the progress bar in a meantime, piece of cake right?</p>
  
  <p>Should I use asynctask or runnable? How do I do this so I do not block the UI thread?</p>
  
  <p>This is code I tried to use in LoginActivity:</p>
  
  <pre><code>new Thread(new Runnable() {
                      @Override
                      public void run() {
                          mUserInputValidated = validateUserInput(inputEmail.getText().toString(), inputPassword.getText().toString());
                      }
                  }).start();
  
                  if(mUserInputValidated)
                  {
                      attemptUserLogin(inputEmail.getText().toString(), inputPassword.getText().toString());
                  }
  </code></pre>
  
  <p>I also tried asynctask approach, but ended up with various errors since I started progress dialog in <code>onPreExecute()</code> and ended it in <code>onPostExecute()</code>, using reference like <code>LoginActivity.this</code> where was the problem with memory leak which I was also unable to fix?</p>
  
  <p>I assume this is pretty usual scenarios, since almost every app use it, so - what are common approaches? How do I fix my code? </p>