简体   繁体   English

Android:重新打开应用程序时出现停止活动吗?

[英]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. 在Android中,我有一些代码可以检查用户是否已打开GPS,并启动设置以供用户打开(如果未打开)。 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. 但是,我发现,如果用户打开“设置”,打开GPS,然后像往常一样继续使用该应用程序,则会出现一个奇怪的问题。 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. 我想知道我是否应该使用CLEAR_TOP标志或类似的东西...我尝试查看文档中的Activity标志,但发现它们有些混乱。 Anyone know? 有人知道吗

听起来您想在活动中使用noHistory属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序被杀死并重新打开时如何返回上一个活动 - How to go back to the last activity when the app is killed and reopened Android Firebase Facebook登录会在重新打开应用时显示“退出”按钮 - Android Firebase Facebook Login shows Logout button when app is reopened Android:一段时间后重新打开应用程序时出现无法解释的崩溃问题 - Android: Unexplained crashes when the app is reopened after a while android活动生命周期:如果进程被杀死,内部应用程序活动可以重新打开吗? - android activity life cycle: can an internal app activity be reopened if process is killed? Android应用程序崩溃一旦重新打开 - Android App Crashes Once Reopened 重新打开应用程序时恢复计时器 - Resume timer when app is reopened “后退”按钮关闭会最小化应用程序,但从任务中重新打开时,它位于上一个活动中 - Back button closes minimizes the app but when reopened from tasks it is on the previous activity Android 每次启动应用程序时运行一段代码,但在应用程序最小化和重新打开时不运行 - Android run a piece of code each time the app is started but not when the app is minimised and reopened 重新打开应用程序时不保留版面颜色更改 - Layout color change is not retained when App reopened 重新打开应用程序后,服务将重新启动 - Service gets restarted when app is reopened
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM