gpt4 book ai didi

android - 在这种情况下,我应该使用FLAG_ACTIVITY_CLEAR_TOP吗?如何使用FLAG_ACTIVITY_CLEAR_TOP意向标志?

转载 作者:行者123 更新时间:2023-12-02 13:21:12 26 4
gpt4 key购买 nike

在我的应用中,我有以下Activity流:LoginActivity> DashboardActivity>(如果用户选择更改密码)> ChangePasswordActivity
如果用户成功更改了密码,我想将其发送回第一个 Activity LoginActivity。我想在处理过程中pop DashboardActivity,以防止任何不必要的缠绵 Activity 。

在这种情况下,使用FLAG_ACTIVITY_CLEAR_TOP启动新的LoginActivity是否正确?我想知道在这种情况下哪些标志是合适的。

值得的是,我的DashboardActivity在我的launchMode中将singleTop设置为AndroidManifest

最佳答案

If you want to just clear the previous activities from stack and launch login activity just do this



manifest文件中,您的登录 Activity 应如下所示
<activity
android:name=".LoginActivity"
android:screenOrientation="portrait"/>

更改密码后,启动带有以下标签的登录 activity
Intent intent = new Intent(ChangePassword.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();

通过将标志设置为 Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK以前的所有 Activity 将从堆栈中清除。

有关更多信息,请检查此
https://developer.android.com/reference/android/content/Intent
从官方文档- FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

For example, consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

关于android - 在这种情况下,我应该使用FLAG_ACTIVITY_CLEAR_TOP吗?如何使用FLAG_ACTIVITY_CLEAR_TOP意向标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56438011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com