title: How to display a Dialog fragment inside location listener to trigger another activity
body: <p>I have an app location listener which pops up toast alerts when the user gets within a specified distance of any point in a list. Instead of a toast popup I'd like to call a dialog fragment that, when the user selects yes, transfers the user into a quiz activity which asks them a question based on their location.</p>
  
  <p>In short I want to be able to display this dialog fragment, instead of the toast, in my location listener activity. Thus far I have tried</p>
  
  <pre><code> DialogFragment dialog = new LocationDialog();  
                   showDialog(dialog);
  </code></pre>
  
  <p>in place of the toast alert but I get the error "The method showDialog(DialogFragment) is undefined for the type QLocationListener. I've been going around in circles following various tutorials, guides and Google's android documentation without avail so some guidance would be greatly appreciated. </p>
  
  <p>All my code is functioning as standalone apps I'm just struggling to link the location listener + main activity to the quiz via the dialog fragment. I also hope to be able to pass location information to the quiz in a bundle so it knows which question and answers to display but that's a task for another day...</p>
  
  <p>Main Activity</p>
  
  <pre><code>import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Context;
  import android.location.LocationManager;
  import android.os.Bundle;
  
  public class MainActivity extends Activity {
  
  private static final long MINIMUM_DISTANCECHANGE_FOR_UPDATE = 1; 
  private static final long MINIMUM_TIME_BETWEEN_UPDATE = 1000; 
  private LocationManager locationManager;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
      QLocationListener qLL = new QLocationListener();
      qLL.parentActivity = this;
  
  
      // create the hard-coded list of points of interest
  
      ArrayList&lt;QuizContent&gt; pointList = new ArrayList&lt;QuizContent&gt;();
  
      // ExampleA
      QuizContent MapPoint = new QuizContent(25,5, "example question?", "a", "b","c","d", "a");
  
      // ExampleB
      QuizContent MapPoint2 = new QuizContent(26,5, "example question?", "a", "b","c","d", "a");
  
      // ExampleC
      QuizContent MapPoint3 = new QuizContent(27,5, "example question?", "a", "b","c","d", "a");
  
  
      pointList.add(MapPoint);
      pointList.add(MapPoint2);
      pointList.add(MapPoint3);
  
  
      // now set up the location manager and listener
      qLL.pointList = pointList;
      locationManager.requestLocationUpdates(
                      LocationManager.GPS_PROVIDER, 
                      MINIMUM_TIME_BETWEEN_UPDATE, 
                      MINIMUM_DISTANCECHANGE_FOR_UPDATE,
                      qLL
      );
  
  
  
  }    
  }
  </code></pre>
  
  <p>QLocation Listener</p>
  
  <pre><code>import java.util.ArrayList;
  
  import android.app.AlertDialog;
  import android.location.Location;
  import android.location.LocationListener;
  import android.os.Bundle;
  import android.support.v4.app.DialogFragment;
  import android.util.Log;
  import android.widget.Toast;
  import android.widget.TextView;
  
  
  public class QLocationListener implements LocationListener {
  
  
  public MainActivity parentActivity ;
  
  // this is my list of quiz content (questions, answers, locations)
  public ArrayList&lt;QuizContent&gt; pointList;
  
  
  // this method is called when the location is changed
  public void onLocationChanged(Location location) {
  
    // now measure distance from all locations in quiz list
      for (int i=0;i&lt;pointList.size();i++){
          QuizContent gp = pointList.get(i);
          Location fixedLoc = new Location("one");
  
          Double lat = Double.valueOf(String.valueOf(gp.getLatitude()));
          Double lng = Double.valueOf(String.valueOf(gp.getLongitude()));
  
          fixedLoc.setLatitude(lat);
          fixedLoc.setLongitude(lng);
          Log.i("location",lat+" "+location.getLatitude());
          Log.i("location",lng+" "+location.getLongitude());
  
          // calculate distance
          float distance = location.distanceTo(fixedLoc);
  
              if (i == 0) { // this is location a
  
               if (distance &lt; 10) {
  
  
                   DialogFragment dialog = new LocationDialog();  
                   showDialog(dialog);
  
  
               }
           }
  
  
           if (i == 1) { // this is location b
  
               if (distance &lt; 10) {
                      Toast.makeText(parentActivity.getBaseContext(), 
                              "Welcome to location b", Toast.LENGTH_LONG).show();
               }
           }
  
           if (i == 3) { // this is location c
  
               if (distance &lt; 10) {
                      Toast.makeText(parentActivity.getBaseContext(), 
                              "Welcome to location c", Toast.LENGTH_LONG).show();
               }
           }
  
      }
  
  }
  public void onProviderDisabled(String s) {
  }
  public void onProviderEnabled(String s) {            
  }
  public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
      // TODO Auto-generated method stub
  
  }
  }
  </code></pre>
  
  <p>Dialog Fragment</p>
  
  <pre><code>import android.app.AlertDialog;
  import android.app.Dialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.DialogFragment;
  
  public class LocationDialog extends DialogFragment {
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      // Use the Builder class for convenient dialog construction
      AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
      alertDialog.setMessage("Quiz Location Found, answer the question?")
             .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     startActivity(new Intent(getActivity(), Quiz.class));
                     // take the quiz!
                 }
             })
             .setNegativeButton("No", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     // User cancelled the dialog
                 }
             });
  
  
      // Create the AlertDialog object and return it
      return alertDialog.create();
  
  }
  
  }
  </code></pre>