阻止用户点击“返回”;他们退出应用程序后

发布于 2024-12-05 01:45:23 字数 213 浏览 0 评论 0原文

一旦用户退出(从首选项中),处理程序就会将用户退出并将其带到初始启动页面。

唯一的问题是用户可以点击“后退”按钮,这会将他们带到其他活动,在那里他们可以看到登录者的信息。我想做的就是让它像某人在注销时第一次打开应用程序一样工作。

我尝试发送使用“FLAG_ACTIVITY_CLEAR_TOP”和“SINGLE_TOP”标志启动活动的意图,但它似乎不起作用。

谢谢

Once a user signs out (from the preferences), the handler signs the user out and them takes them to the initial launch page.

The only problem is the user can hit the 'back' button which takes them to the other activities where they can see the info from the logged in person. What i want to do is make it work like someone has just opened the app for the first time when they have signed out.

I've tried to send the intent of starting the activity with 'FLAG_ACTIVITY_CLEAR_TOP' and 'SINGLE_TOP' flags but it doesn't seem to work.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔岸观火 2024-12-12 01:45:23

尝试使用 FLAG_ACTIVITY_CLEAR_TASK 选项。

编辑:刚刚注意到这仅在 API 11 中。您可能需要执行一些操作,例如在所有活动中注册 BroadcastReceiver,然后在注销屏幕上发送 BroadcastReceiver 将捕获的 Intent。然后 Activity 就可以干净地退出。

Try the FLAG_ACTIVITY_CLEAR_TASK option.

EDIT: just noticed that this is only in API 11. You'll probably need to do something like registering a BroadcastReceiver in all your Activities, then on the logout screen send an Intent that the BroadcastReceiver will catch. The Activity can then cleanly exit.

信仰 2024-12-12 01:45:23

您可以做两件事,第一件事您已经尝试过,但由于某种原因不起作用。

一种是在启动 Activity 时清除后退按钮堆栈,如下所示: myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 尽管我不确定为什么这对您不起作用。

您可以做的另一件事是覆盖登录活动中的后退按钮处理,使其不执行任何操作。以下是实现该目的的示例代码:

@Override
public void onBackPressed() 
{
    return;
}

There are two things you can do, the first of which you've tried but isn't working for some reason.

One is to clear the back button stack when you launch your activity like this: myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); though I'm not sure why that's not working for you.

The other thing you can do is override the back button handling in your login activity so that it doesn't do anything. Here is example code to accomplish that:

@Override
public void onBackPressed() 
{
    return;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文