title: Android - Navigate back to app from System Settings
body: <p>On my login activity, I check if the user has activated/ turned on their GPS.
  If not, I simply display an <code>AlertDialog</code> asking the user to switch on the GPS.</p>
  
  <p>From the <code>AlertDialog</code> I launch/start an Intent as follows:                     </p>
  
  <pre><code>Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  startActivity(settingsIntent);
  </code></pre>
  
  <p>When pressing the back button from the System Settings the user returns to the phone's home screen...  i.e "closing the app".</p>
  
  <p>I have tried <code>onActivityResult</code> but to no avail.
  Furthermore, I have read up on similar problems other users had but it proofed
  pointless as most answers related back to using <code>onActivityResult</code>.</p>
  
  <p>Can someone please shine some light on the matter?</p>
  
  <p><strong>Edit:</strong>
  Here is the full code for the <code>AlertDialog</code>:</p>
  
  <pre><code>builder = new AlertDialog.Builder(this);
  builder.setTitle("GPS Not Found");
  builder.setMessage("Want To Enable?");
  
  //Dialog - Yes option
  builder.setPositiveButton("Yes", new DialogInterface.OnClickListener()
  {
  public void onClick(DialogInterface dialogInterface, int i)
  {
  Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  startActivityForResult(settingsIntent,1);
  }
  });
  
  //Dialog - No option                
  builder.setNegativeButton("No", new DialogInterface.OnClickListener()
  {
  public void onClick(DialogInterface dialogInterface, int i)
  {
  
  }
  });
  
  //Show he dialog
  builder.create().show();
  </code></pre>
  
  <p><strong>Edit:</strong>
  Here are the <code>OnPause()</code> and <code>OnResume()</code> methods.  I simply check to see if the provider is still active and the same with the <code>locationManager</code>.
  Neither "TEST 1" nor "TEST 2" gets printed when I go back from Settings.</p>
  
  <pre><code>@Override
  protected void onResume()
  {
    Log.i(ERRORTAG, "TEST 1");
  
    super.onResume();
    if(provider != null)
    {
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, refreshTime, refreshDistance, this);
      gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }
  }
  
  
  @Override
  protected void onPause()
  {
    Log.i(ERRORTAG, "TEST 2");
  
  
    super.onPause();
    if(locationManager != null)
    {
      locationManager.removeUpdates((LocationListener) this);
      gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }
  
  
    if(loginDialog != null)
    {
      loginDialog.dismiss();
    }
  }
  </code></pre>