title: Android: toast inside AsyncTask
body: <p>I have an AsyncTask class <code>SearchForQuestions</code> that is called from an Activity <code>QuizMap</code>. When looping through an array in <code>SearchForQuestions</code> I can't find the correct context for toast to appear within the AsynTask. </p>
  
  <p>The standard <code>Toast.makeText(getApplicationContext(), "This is Toast!!!", Toast.LENGTH_SHORT).show();</code> gives error <code>getApplicationContext()</code> undefined.</p>
  
  <p>I have tried some of the solutions to this offerred by SO, most of them are listed <a href="https://stackoverflow.com/questions/3134683/android-toast-in-a-thread">here</a>  and  concern getting UiThread and running on that. </p>
  
  <p>I can't get this to work however. Here's example code snippets of what i have tried. I have put a method in <code>QuizMap</code> and try calling it from <code>SearchForQuestions</code> but <code>SearchForQuestions</code> isn't recognised. How can I get around this? )Still a newbie at java...)</p>
  
  <pre><code>// QuizMap activity
  
  public class QuizMap extends FragmentActivity 
  implements OnMarkerClickListener {
  
  private GoogleMap map;
  
  private static final String TAG = "QuizMap"; // debugging
  ...
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_quizmap);
       map = ((SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map))
                 .getMap();
  ...
  }
  
      // make toast inside AsyncTask
  public void showNotNearToast(final String toast) {
      QuizMap.this.runOnUiThread(new Runnable() {
          public void run() {
              Toast.makeText(QuizMap.this, "This is Toast!!!", Toast.LENGTH_SHORT).show();
  
          }});
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>// SearchForQuestions class
  private class SearchForQuestions extends AsyncTask&lt;String, Void, DataHandler&gt; {
      // checks for proximity to question locations
  
      Location location = 
              locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  
      @Override
      protected DataHandler doInBackground(String... pointsList) {
          String result = pointsList[0];
          ...
  }
  
      @Override
      protected void onPostExecute(DataHandler result) {
  
          ArrayList&lt;String&gt; resultsArray = result.results;
          Integer numPoints = resultsArray.size();
          for (int i =0;i&lt;numPoints;i++){
  
              String[] pointDetails = resultsArray.get(i).split("::");
              ...
  
              // we can make use of the Android distanceTo function to calculate the distances
              float distance = location.distanceTo(fixedLoc);
  
              if (i &gt; DIST) { // this is UCL
  
                  showNotNearToast("My Message"); // showNotNearToast undefined 
  
  
                  if (distance &lt; DIST) {
  
               ...
                   }
                      };
  </code></pre>