明确任务的所有活动? [英] Clear all activities in a task?
问题描述
我有一个闪屏的活动,然后登录活动。我的历史堆栈是这样的:
I have a splash screen activity, then a login activity. My history stack looks like:
SplashActivity
LoginActivity
当用户通过LoginActivity成功登录,我要开始WelcomeActivity,但清除整个堆栈:
when the user successfully logs in via LoginActivity, I want to start WelcomeActivity, but clear the entire stack:
SplashActivity
LoginActivity // launches WelcomeActivity ->
WelcomeActivity
// but now all three are in the history stack, while I only
// want WelcomeActivity in the stack at this point.
有一些标志,我可以用它来做到这一点?
Is there some flag I can use to do that?
// LoginActivity.java
Intent intent = new Intent(this, WelcomeActivity.class);
intent.addFlag(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
不知道是否使用FLAG_ACTIVITY_CLEAR_TASK将清除所有活动我的任务或没有。我可以通过使用startActivityForResult()调用展开堆栈这种手动操作,但会更脆弱,更code来维持。
Not sure if using the FLAG_ACTIVITY_CLEAR_TASK will clear out all activities in my task or not. I can do this 'manually' by unwinding the stack by using startActivityForResult() calls, but will be more fragile and more code to maintain.
感谢
推荐答案
是的,这应该能正常运行。你可以使用:
Yes that should work fine. You could use:
-
FLAG_ACTIVITY_CLEAR_TOP
-
FLAG_ACTIVITY_SINGLE_TOP
-
FLAG_ACTIVITY_CLEAR_TASK
-
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_SINGLE_TOP
FLAG_ACTIVITY_CLEAR_TASK
FLAG_ACTIVITY_NEW_TASK
这确保了一个实例是已在运行,而不是顶部,然后在上面的任何东西,将被清除,它会被使用,而不是开始一个新的实例(这个有用的,一旦你已经走了欢迎活动 - >活动A,然后你想回到从A到欢迎,但额外的标志应该不会影响你的案件以上)。
which ensures that if an instance is already running and is not top then anything on top of it will be cleared and it will be used, instead of starting a new instance (this useful once you've gone Welcome activity -> Activity A and then you want to get back to Welcome from A, but the extra flags shouldn't affect your case above).
这篇关于明确任务的所有活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!