开发者

Android: stop activity appearing when an app is reopened?

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开发者_JAVA百科 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜