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 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);
According to the Android Documentation the flag does the following:
http://developer.android.com/reference/android/content/Intent.html#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.
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?
The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo. class); startActivity(i);
Using Intents This example demonstrate about How to send data from one activity to another in Android using intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
exit() the system will indeed kill the current process and remove the activity from the back stack (in this case SecondActivity ) and it will also resume the activity that it's below on the stack — which in this case will be from the same application since there's no call to finish() on our code.
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("");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With