简体   繁体   English

清除活动堆栈

[英]Clearing Activity Stack

I am having trouble clearing my app's activity stack. 我在清除应用程序的活动堆栈时遇到问题。 At the start of my app I make the user login and give them a session id. 在我的应用程序启动时,我让用户登录并给他们一个会话ID。 After they login they are able to continue on using the app. 登录后,他们可以继续使用该应用程序。 However if there session expires I want to redirect them to the login activity and clear the Activity history so they can't have access to the app. 但是,如果会话过期,我想将其重定向到登录活动并清除活动历史记录,以使他们无法访问该应用程序。 I looked at the Android API and the Intent flag FLAG_ACTIVITY_CLEAR_TASK seems to be want I want but it was just included in API level 11 and no phones have the new OS yet. 我查看了Android API,似乎想要我的Intent标志FLAG_ACTIVITY_CLEAR_TASK ,但它仅包含在API级别11中,还没有手机具有新的操作系统。 Does anyone have a solution to this problem. 有谁能解决这个问题。 Thanks. 谢谢。

I found my answer here . 我在这里找到了答案。 Turns out that I have to broadcast an intent to tell all of the Activities to call the method finish() . 事实证明,我必须广播一个意图,告诉所有Activity调用方法finish()

The documentation for FLAG_ACTIVITY_CLEAR_TOP describes the situation you want if you use it in conjunction with FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_CLEAR_TOP的文档描述了与FLAG_ACTIVITY_NEW_TASK结合使用时的情况

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP

"This launch mode can also be used to good effect in conjunction with FLAG_ACTIVITY_NEW_TASK: if used to start the root activity of a task, it will bring any currently running instance of that task to the foreground, and then clear it to its root state. This is especially useful, for example, when launching an activity from the notification manager." “此启动模式还可以与FLAG_ACTIVITY_NEW_TASK结合使用,效果很好:如果用于启动任务的根活动,它将把该任务的任何当前正在运行的实例置于前台,然后将其清除为根状态。例如,当从通知管理器启动活动时,这特别有用。”

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM