title: Android activate gps with AlertDialog: how to wait for the user to take action?
body: <p>I've read different posts that there is no way to wait for the user to take an action when an <code>AlertDialog</code> is shown because it blocks the UI. </p>
  
  <p>However, apps like <code>Facebook</code> for example displays the <i>Gps is currently disabled. Do you want to enable gps?</i> alert dialog and wait for the user to press yes/no. 
  I'm thinking that it's possible to use 2 different activities, first one containing only the  gps alert dialog, but this doesn't seem right and definetely doens't seem the way facebook does this.</p>
  
  <p>Can anyone tell me how can i achieve this? </p>
  
  <p>This is my code:</p>
  
  <pre><code>       @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      InitializeComponents();
  
      EnableGPSIfPossible();
  
  
          ListAsync lAsync = new ListAsync(this);
          lAsync .execute();
      }
  
  
      private void EnableGPSIfPossible()
  {   
      final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
       if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
              buildAlertMessageNoGps();
          }
  }
  
   private  void buildAlertMessageNoGps() {
          final AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setMessage("Yout GPS seems to be disabled, do you want to enable it?")
                 .setCancelable(false)
                 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                     public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                       startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                     }
                 })
                 .setNegativeButton("No", new DialogInterface.OnClickListener() {
                     public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                          dialog.cancel();
                     }
                 });
          final AlertDialog alert = builder.create();
          alert.show();
      }
  </code></pre>
  
  <p>So, in my code the <code>AsynTask</code> starts imediately without waiting for the user to activate the gps. (which is a normal behaviour)</p>
  
  <p>Thank you!</p>