[英]Clearing activity stack when you have multiple entry point activities?
I have an app which has multiple entry point activities. 我有一个具有多个入口点活动的应用程序。 I want to be able to clear my activity stack programmatically.
我希望能够以编程方式清除我的活动堆栈。 Imagine an app which requires user authentication, and the user wants to invalidate their session remotely (stolen device, for example).
想象一个需要用户身份验证的应用程序,而用户希望远程取消其会话(例如,被盗设备)。
In the case where an app has a single starting activity, we could just use: 如果一个应用只有一个启动活动,我们可以使用:
Intent intent = new Intent(context, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
to get back to the root activity. 回到根活动。 But my app may have been launched from different entry points, and so there might be different activity classes at the root of the stack.
但是我的应用程序可能是从不同的入口点启动的,因此堆栈的根部可能有不同的活动类。
Some options: 一些选项:
Thanks 谢谢
You can check the name of activity at the root of the task stack and then start that activity with the FLAG_ACTIVITY_CLEAR_TOP. 您可以在任务堆栈的根部检查活动的名称,然后使用FLAG_ACTIVITY_CLEAR_TOP启动该活动。 If this root activity is not the activity you want then start the activity you want in onCreate and call finish().
如果此根活动不是您想要的活动,则在onCreate中启动您想要的活动,然后调用finish()。
You can find the name of the root activity by 您可以通过以下方式找到根活动的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.