Android: Intent Flag to destroy activity and start new one

前端 未结 2 1427
耶瑟儿~
耶瑟儿~ 2021-02-07 00:55

So I have a Login Activity This 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 Logi

相关标签:
2条回答
  • 2021-02-07 01:40

    You have 2 choices:

    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 - Empty the values then start new activity

    edittext_username.setText("");
    edittext_password.setText("");
    
    0 讨论(0)
  • 2021-02-07 01:48

    If you are supporting only API levels 11+, you should be able to use FLAG_ACTIVITY_CLEAR_TASK. This will finish all existing Activities in all tasks and create a new instance of the Login activity.

    0 讨论(0)
提交回复
热议问题