阻止用户点击“返回”;他们退出应用程序后
一旦用户退出(从首选项中),处理程序就会将用户退出并将其带到初始启动页面。
唯一的问题是用户可以点击“后退”按钮,这会将他们带到其他活动,在那里他们可以看到登录者的信息。我想做的就是让它像某人在注销时第一次打开应用程序一样工作。
我尝试发送使用“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 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.
您可以做两件事,第一件事您已经尝试过,但由于某种原因不起作用。
一种是在启动 Activity 时清除后退按钮堆栈,如下所示:
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
尽管我不确定为什么这对您不起作用。您可以做的另一件事是覆盖登录活动中的后退按钮处理,使其不执行任何操作。以下是实现该目的的示例代码:
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: