问题描述
我有一个 LoginActivity
我的启动画面。而 SettingsActivity
我的第五屏幕
。
I have a LoginActivity
as my launcher screen. And SettingsActivity
as my fifth screen
.
我有一个注销在设置屏幕按钮
。 在clcik
这个按钮,我怎么能去屏幕-1(即LoginActivity)
通过清除所有剩余活动(即第2,第3,第4)
的活动栈?
I have a logout button
in settings screen. On clcik
of this button, how can i go to Screen-1 (i.e LoginActivity)
by clearing all remaining activities (i.e 2nd, 3rd, 4th)
from activity stack?
注:我已经完成 LoginActivity
而不是剩余活动。在此先感谢
Note : i have finished LoginActivity
but not remaining activities. Thanks in advance
推荐答案
很简单,在你的注销按钮设置一个onclick,然后添加到您的意图:
Simple, set an onclick on your logout button and then add this to your intent:
Intent newIntent = new Intent(this, login.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(newIntent);
finish();
这应该清除上面的login.class整个堆栈
This should clear your entire stack above login.class
如果你今天感觉真正的乐趣,添加
And if you're feeling real fun today, add
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
这将摆脱恼人的展示了Android主屏幕上的S3问题
Which will get rid of that annoying "show the android homescreen" issue on the S3
这篇关于在Android的清除活性栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!