title: External AsyncTask class with ProgressDialog [Update: and returning back?]
body: <p>**Updated: (See below)**I have been looking around for couple of days and can't find a straight answer to this. 
  Some say it possible to some say to accomplish some say it's not. I am getting crazy on this. </p>
  
  <p>What I want is just to have the AsyncTaskTask showing a progressbar an external class. To do this I am passing the context as you can see in the main class. But whatever I try I get <code>NullPointerException</code>.</p>
  
  <p>Working code examples is appreciated. Thank you</p>
  
  <p>Using Android 2.2 by the way.</p>
  
  <p>main:</p>
  
  <pre><code>import android.app.Activity;
  import android.os.Bundle;
  
  public class AsyncDemo extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          new AsyncClass(this).execute();
      }
  }
  </code></pre>
  
  <p>AsyncClass.java</p>
  
  <pre><code>import android.app.ProgressDialog;
  import android.content.Context;
  import android.os.AsyncTask;
  import android.os.SystemClock;
  
  public class AsyncClass extends AsyncTask&lt;Void, String, Void&gt; {
      private Context context;
      ProgressDialog dialog = new ProgressDialog(context);
  
      public AsyncClass(Context cxt) {
          context = cxt;
      }
  
      @Override
      protected void onPreExecute() {
          dialog.setTitle("Please wait");
          dialog.show();
      }
  
      @Override
      protected Void doInBackground(Void... unused) {
          SystemClock.sleep(2000);
          return (null);
      }
  
      @Override
      protected void onPostExecute(Void unused) {
          dialog.dismiss();
      }
  }
  </code></pre>
  
  <p><strong>Update:</strong>
   I have a follow up question: Using the above code, is it possible to return a value from the onPostExecute method back to the main class, somehow? (Sorry about beeing noobish)
  I have tried something like this:</p>
  
  <pre><code>String result = new AsyncClass(this).execute();
  </code></pre>
  
  <p>and then a method that return back a string. But I can't do that because i got:</p>
  
  <pre><code>Type mismatch: cannot convert from AsyncTask&lt;String,Void,Void&gt; to String
  </code></pre>
  
  <p>What can I do to tackle this problem? Thanks.</p>