Intent.FLAG_ACTIVITY_CLEAR_TOP不起作用

问题描述 投票:6回答:4

我的申请流程:

登录->配置文件-> UpdateProfile-> ChangePass

我的所有活动都扩展了FragmentActivity

当我在ChangePass活动中按按钮时,我将此代码称为:

Intent intent=new Intent(getApplicationContext(),LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

因此它应该启动LoginActivity,并且当我从LoginActivity按下时,应用程序应该关闭...但是当我从Login Activity中按下返回按钮时,流程为:

ChangePass-> UpdateProfile-> Profile->登录

为什么不清除我的后背包?

注意:

我已经应用了所有这些解决方案,但是没有用:1.link2.link

android back-stack
4个回答
4
投票
虽然回复很晚。但可能会对其他人有所帮助,因为它对我有用。

开发人员有时将FLAG_ACTIVITY_CLEAR_TASKFLAG_ACTIVITY_CLEAR_TOP混淆

使用此代替intentRestart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);


2
投票
尝试以下方式-

Intent intent = new Intent(getActivity(), LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); finish();

[有关更多替代方法和详细信息,请检查intent-flag-activity-clear-top-doesn't-deletes-the-activity-stack。帖子完美地解释了结果代码以及上述解决方案。     

0
投票
而不是替换旧标志,请尝试附加一个。Setflag替换旧的标志。

尝试使用addFlags。


0
投票
清除任务并创建新任务。

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)

这可能会在过渡时创建一个临时白屏。消除此缺陷。将此添加到您的应用主题。

<item name="android:windowDisablePreview">true</item>

享受Android!    
© www.soinside.com 2019 - 2024. All rights reserved.