以破坏活动并开始新的活动

以破坏活动并开始新的活动

本文介绍了Android:意图标志,以破坏活动并开始新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个登录活动当我输入用户名和密码并单击登录"按钮时,此活动会放大具有USER_NAME和PASSWORD EditText视图的login.xml布局.

So I have a Login ActivityThis Activity inflates a login.xml layout which has a USER_NAME and PASSWORD EditText Views, when I enter the Username and Password and click the Login Button I start a new Activity.

新的活动具有一个注销"按钮,基本上可以像这样开始上一个活动:

The new Activity has a Logout button which basically just starts the previous Activity like so:

    Intent loginIntent = new Intent(getActivity(), Login.class);
    loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    getActivity().startActivity(loginIntent);

根据Android文档,该标记会执行以下操作:

According to the Android Documentation the flag does the following:

如果已设置,并且正在启动的活动已经在当前任务,而不是启动该任务的新实例活动,除此以外的所有其他活动将被关闭,该意图将作为新的意图.

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

问题是我注销后用户名和密码仍然出现在EditText视图中,是否存在一个会破坏Login活动并只是开始一个新活动的Flag,或者是否有一种方法可以在我注销时重置字段?哪种方法更好?

The problem is that the Username and Password still appear in the EditText Views after I logout, is there a Flag that destroys the Login activity and just starts a new one or is there a way to reset the fields whenever I logout? Which is the better approach?

推荐答案

您有2个选择:

1-成功登录后终止登录活动

1 - Kill the login activity after a successful login

Intent loginIntent = new Intent(getActivity(), Login.class);
    loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    getActivity().startActivity(loginIntent);
finish();

2-清空值,然后开始新的活动

2 - Empty the values then start new activity

edittext_username.setText("");
edittext_password.setText("");

这篇关于Android:意图标志,以破坏活动并开始新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:25