0

On my login activity, I check if the user has activated/ turned on their GPS. If not, I simply display an AlertDialog asking the user to switch on the GPS.

From the AlertDialog I launch/start an Intent as follows:

Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingsIntent);

When pressing the back button from the System Settings the user returns to the phone's home screen... i.e "closing the app".

I have tried onActivityResult 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 onActivityResult.

Can someone please shine some light on the matter?

Edit: Here is the full code for the AlertDialog:

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();

Edit: Here are the OnPause() and OnResume() methods. I simply check to see if the provider is still active and the same with the locationManager. Neither "TEST 1" nor "TEST 2" gets printed when I go back from Settings.

@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();
  }
}
Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174
Ronin
  • 93
  • 1
  • 13
  • 1
    can you show the whole code to your `AlertDialog`? I suspect you are calling `finish()` in there somewhere. – iagreen Jan 14 '13 at 15:55
  • The behavior of the Settings app may vary by device manufacturer, as they tend to tinker with this app more than others. While it should normally return to you (AFAIK), that is not required. Though as iagreen points out, there may be something in the way that you are starting the activity that will cause above-average difficulties in this area. – CommonsWare Jan 14 '13 at 15:58

2 Answers2

0

Are you calling finish(); somewhere after your startActivity() or in onPause()?
Looking at the Activity Life Cycle you see that onPause() is called when your start the Settings-Intent.

Thommy
  • 5,070
  • 2
  • 28
  • 51
0

Sorted out the problem. In the manifest file, the activity had the tag noHistory="true" which (to my understanding) doesn't add it to the stack. Hence can't go "back" to the activity.

Ronin
  • 93
  • 1
  • 13