title: getApplicationContext in AsyncTask class?
body: <p>I have a couple private AsyncTask methods that I'd like to break out into public external classes. In my application, I have a public class extending Application which holds some shared routines I want to access from different parts of my application. When I break out the AsyncTask class however, I'm no longer able to call getApplicationContext() to get a reference to my application library (the class does not inherit anything from Activity now). getBaseContext() will have problems as well. Should I be passing a context into the AsyncTask when it gets instantiated and build from there? Not sure if that was safe or not.</p>
  
  <pre><code>import java.util.ArrayList;
  import android.os.AsyncTask;
  
  public class DlTask extends AsyncTask
  {
      long totalbytes = 0;
      long totalread = 0;
      ArrayList &lt;String&gt; data;
  
      @Override
      protected void onPreExecute ()
      {   
          AppLib lib = (AppLib) getApplicationContext();
  
          lib.saveStatusText ("Contacting " + lib.getServerAddress () + ":" + lib.getServerPort () + "...");
         super.onPreExecute ();
      }
  
        @Override
        protected Object doInBackground (Object... params)
        {
          data = lib.sendCommand (CMD_LIST);
           return true;
        }
  
        @Override
        protected void onPostExecute (Object result)
        {
  
           if (data != null)
           {
                      lib.saveStatusText (data.size () + " files found");
           }
           else
           {
              Log.d (TAG, "data is null");
              Toast.makeText (getBaseContext(), msg, Toast.LENGTH_SHORT).show ();                     
           }
  
           super.onPostExecute(result);
        }
  
  }
  </code></pre>