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