tags:

views:

54

answers:

1

Hi there

In Android, I have some code to check whether the user has GPS switched on, and launch the Settings for them to turn it on if they don't. It looks like this:

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder
    .setMessage(
    "Your GPS seems to be disabled - you need it to get a location fix. Turn it on now?")
    .setCancelable(false).setPositiveButton("Yes",
            new DialogInterface.OnClickListener() {
        public void onClick(
                @SuppressWarnings("unused") final DialogInterface dialog,
                @SuppressWarnings("unused") final int id) {
            Intent j = new Intent();
            j.setAction("android.settings.LOCATION_SOURCE_SETTINGS");
            startActivity(j);
        }
    }).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();
}

However, I'm finding that if the user opens the Settings, turns GPS on, then carries on using the app as normal, there is an odd problem. Often, when the user reopens the app, the Settings are at the front. How can I set them so they don't keep reappearing?

I wonder if I should be using the CLEAR_TOP flag or something similar... I've tried looking at the docs for the Activity flags but find them a bit confusing. Anyone know?

A: 

Sounds like you want to use the noHistory attribute on your activity.

jqpubliq