title: What is the best way of getting / using Context inside AsyncTask?
body: <p>I've defined a separate thread by extending the <code>AsyncTask</code> class. Within this class I perform some Toasts and Dialogs within the AsyncTask's <code>onPostExecute</code> and <code>onCancelled</code> methods. The toasts require the application's context such that all I need do is:</p>
  
  <pre><code>Toast.makeText(getApplicationContext(),"Some String",1);
  </code></pre>
  
  <p>The dialogs are created using <code>AlertDialog.Builder</code> which also requires a context in its constructor. Am I right in thinking that this context should be the Activity's context? i.e.</p>
  
  <pre><code>AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  
  </code></pre>
  
  <p>where <code>getActivity</code> could be a user defined class that returns the current activity. If so what is the best way to handle this situation? Creating a class like <code>getActivity</code> or passing the current activity's context to the AsyncTask's constructor?</p>
  
  <p>I guess I'm trying to understand the use of <code>Context</code> - I have noticed that memory leaks can be an issue (don't really understand this yet) and how using <code>getApplicationContext()</code> is the best approach where possible.</p>